## Socket()

Constructor

#### # new Socket()

View Source doc/classes.js, line 460

# Methods

#### # Close(doFlushopt)

close the socket.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`doFlush` | boolean | <optional> | false | flush before close.

View Source doc/classes.js, line 471

#### # DataReady() → {number}

Get number of bytes waiting to be read.

View Source doc/classes.js, line 535

Returns:
number of bytes waiting to be read.
Type: number

#### # Established() → {boolean}

Check if the socket connection is established.

View Source doc/classes.js, line 541

Returns:
true if the connection is established.
Type: boolean

#### # Flush(flushWaitopt)

Send pending TCP data.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`flushWait` | boolean | <optional> | false | wait until data is flushed.

View Source doc/classes.js, line 519

#### # Flush()

flush the socket output to the network.

View Source doc/classes.js, line 465

#### # FlushNext()

Causes next transmission to have a flush (PUSH bit set).

View Source doc/classes.js, line 529

#### # GetLocalPort() → {number}

Get the local port number.

View Source doc/classes.js, line 553

Returns:
the local port number.
Type: number

#### # GetRemoteHost() → {IpAddress}

Get the remote host ip

View Source doc/classes.js, line 547

Returns:
IP of the remote host.
Type: IpAddress

#### # GetRemotePort() → {number}

Get the remote port number.

View Source doc/classes.js, line 559

Returns:
the remote port number.
Type: number

#### # Mode(mode)

Set binary or ascii mode for UDP/TCP sockets.

##### Parameters:

Name | Type | Description
--- | --- | ---
`mode` | number | one of SOCKET.MODE.

View Source doc/classes.js, line 513

#### # NoFlush()

Sets non-flush mode on next TCP write.

View Source doc/classes.js, line 524

#### # ReadByte() → {number}

Get the next byte from the socket as number.

View Source doc/classes.js, line 488

Returns:
the next byte from the socket.
Type: number

#### # ReadBytes(len) → {Array.<number>}

Return data as array of numbers. This method blocks until 'len' bytes have been read.

##### Parameters:

Name | Type | Description
--- | --- | ---
`len` | number | number of bytes to read from socket.

View Source doc/classes.js, line 586

Returns:
data as array.
Type: Array.<number>

#### # ReadLine() → {string}

Return the next line from the socket as string. This method blocks until a newline is read.

View Source doc/classes.js, line 566

Returns:
the next line from the socket as string.
Type: string

#### # ReadString(len) → {string}

Return data as string. This method blocks until 'len' bytes have been read.

##### Parameters:

Name | Type | Description
--- | --- | ---
`len` | number | number of bytes to read from socket.

View Source doc/classes.js, line 576

Returns:
data as string.
Type: string

#### # WaitFlush()

Wait until all written data is flushed.

View Source doc/classes.js, line 476

#### # WaitInput(timeoutopt)

Wait on socket for incoming data with timeout.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`timeout` | boolean | <optional> | 1 | max wait time.

View Source doc/classes.js, line 482

#### # WriteByte(ch)

write a byte to a socket.

##### Parameters:

Name | Type | Description
--- | --- | ---
`ch` | number | the byte to write.

View Source doc/classes.js, line 495

#### # WriteBytes(data)

send binary data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array.<number> | data to write as number array.

View Source doc/classes.js, line 501

#### # WriteString(str)

send string.

##### Parameters:

Name | Type | Description
--- | --- | ---
`str` | string | data to send.

View Source doc/classes.js, line 507