## Socket()

Constructor

#### # new Socket()

# Methods

#### # Close(doFlushopt)

close the socket.

##### Parameters:

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

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

Get number of bytes waiting to be read.

Returns:

number of bytes waiting to be read.

Type: number

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

Check if the socket connection is established.

Returns:

true if the connection is established.

Type: boolean

#### # Flush()

flush the socket output to the network.

#### # Flush(flushWaitopt)

Send pending TCP data.

##### Parameters:

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

#### # FlushNext()

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

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

Get the local port number.

Returns:

the local port number.

Type: number

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

Get the remote host ip

Returns:

IP of the remote host.

Type: IpAddress

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

Get the remote port number.

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.

#### # NoFlush()

Sets non-flush mode on next TCP write.

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

Get the next byte from the socket as number.

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.

Returns:

data as array.

Type: Array.<number>

#### # ReadInts(len) → {IntArray}

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

##### Parameters:

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

Returns:

data as IntArray.

Type: IntArray

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

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

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.

Returns:

data as string.

Type: string

#### # WaitFlush()

Wait until all written data is flushed.

#### # WaitInput(timeoutopt)

Wait on socket for incoming data with timeout.

##### Parameters:

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

#### # WriteByte(ch)

write a byte to a socket.

##### Parameters:

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

#### # WriteBytes(data)

send binary data.

##### Parameters:

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

#### # WriteInts(data)

send binary data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | IntArray | data to write as IntArray.

#### # WriteString(str)

send string.

##### Parameters:

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