CS3 JS: Socket

CS3 JavaScript

Socket

 Creates a TCP/IP connection, or establishes a TCP/IP server.

QuickLinks

Socket, close, listen, open, poll, read, readln, write, writeln

Properties

PropertyTypeAccessDescription
connectedboolreadonlyWhen true, the connection is active.
encodingstringr/w

Sets or retrieves the name of the encoding used to transmit data.

Typical values are "ASCII", "BINARY", or "UTF-8".

eofboolreadonlyWhen true, the receive buffer is empty.
errorstringr/wA message describing the most recent error. Setting this value clears any error message.
hoststringreadonly

The name of the remote computer when a connection is established.

If the connection is shut down or does not exist, the property contains the empty string.

timeoutnumberr/wThe timeout in seconds to be applied to read or write operations. (default: 10)

Methods

Socket Socket ()
Creates a new Socket object.

bool close ()
Terminates the open connection.

bool listen (port:number [, encoding:string=ASCII])
Instructs the object to start listening for an incoming connection.

ParameterTypeDescription
portnumber The TCP/IP port number to listen on.
encodingstringThe encoding to be used for the connection (default: ASCII)

bool open (host:string [, encoding:string=ASCII])
Opens the connection for subsequent read/write operations.

ParameterTypeDescription
hoststringThe server to connect to.
encodingstringThe encoding to be used for the connection (default: ASCII)

Socket poll ()
Checks a listening object for a new incoming connection.

string read (count:number)
Reads up to the specified number of characters from the connection. CR characters are ignored unless the encoding is set to "BINARY".

ParameterTypeDescription
countnumberThe number of characters to read.

string readln ()
Reads one line of text up to the next line feed.

bool write (text:string)
Concatenates all arguments into a single string and writes that string to the connection.

ParameterTypeDescription
textstring Any number of string values. All arguments are concatenated to form the string to be written. CRLF sequences are converted to LFs unless the encoding is set to "BINARY".

bool writeln (text:string)
Concatenates all arguments into a single string, appends a LF character, and writes that string to the connection.

ParameterTypeDescription
textstring Any number of string values. All arguments are concatenated to form the string to be written. CRLF sequences are converted to LFs unless the encoding is set to "BINARY".

Return

Socket Socket.Socket ()

Socket Socket.poll ()

Contents :: Index