Class

Socket

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.

number of bytes waiting to be read.

number

# Established() → {boolean}

Check if the socket connection is established.

true if the connection is established.

boolean

# 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.

the local port number.

number

# GetRemoteHost() → {IpAddress}

Get the remote host ip

IP of the remote host.

IpAddress

# GetRemotePort() → {number}

Get the remote port number.

the remote port number.

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.

the next byte from the socket.

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.

data as array.

Array.<number>

# ReadInts(len) → {ByteArray}

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

Parameters:
Name Type Description
len number

number of bytes to read from socket.

data as ByteArray.

ByteArray

# ReadLine() → {string}

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

the next line from the socket as string.

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.

data as string.

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 ByteArray

data to write as ByteArray.

# WriteString(str)

send string.

Parameters:
Name Type Description
str string

data to send.