Socket
QuickLinks
Properties
| Property | Type | Access | Description |
|---|---|---|---|
| connected | bool | readonly | When true, the connection is active. |
| encoding | string | r/w | Sets or retrieves the name of the encoding used to transmit data. Typical values are "ASCII", "BINARY", or "UTF-8". |
| eof | bool | readonly | When true, the receive buffer is empty. |
| error | string | r/w | A message describing the most recent error. Setting this value clears any error message. |
| host | string | readonly | 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. |
| timeout | number | r/w | The 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.
| Parameter | Type | Description |
|---|---|---|
| port | number | The TCP/IP port number to listen on. |
| encoding | string | The encoding to be used for the connection (default: ASCII) |
bool open (host:string [, encoding:string=ASCII])
Opens the connection for subsequent read/write operations.
| Parameter | Type | Description |
|---|---|---|
| host | string | The server to connect to. |
| encoding | string | The 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".
| Parameter | Type | Description |
|---|---|---|
| count | number | The 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.
| Parameter | Type | Description |
|---|---|---|
| text | string | 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.
| Parameter | Type | Description |
|---|---|---|
| text | string | 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 ()