Clients -
socket :
Client
Represents the socket client and related remote functions.
Constructor
__init
(ClientConfig? clientConfig)
- clientConfig ClientConfig?
-
This is used to provide the configurations like host, port, and timeout
Remote Methods
write | Writes the given data to the client socket. |
read | Reads data from the client socket. |
close | Closes the client socket connection. |
shutdownRead | Shuts down any further reading from the socket. |
shutdownWrite | Shuts down any further writing from the socket. |
Fields
- remotePort int (default 0)
-
The remote port number to which this socket is connected
- localPort int (default 0)
-
The local port number to which this socket is bound
- remoteAddress string? (default ())
-
The remote IP address string in textual presentation to which the socket is connected
- localAddress string? (default ())
-
The local IP address string in textual presentation to which the socket is bound
- id int (default 0)
-
A unique identifier to identify each client
Writes the given data to the client socket.
int|socket:Error writeResult = socketClient:write(payloadByte);
Parameters
- content byte[]
-
The content, which will be sent to the client socket
-
Return Type
(int | Error) The number of bytes that got written or else a
socket:Error
if the given data can't be written
Reads data from the client socket. If the data has the specified length, then it waits until that number of bytes are received from the client. Else, it returns the data available in the OS buffer. In the case of the connection being closed by the client, then return either -1 or the data that is currently available in the buffer. Number of bytes returned will be < 0 if the client closes the connection.
[byte[], int]|socket:ReadTimedOutError result = socketClient->read();
Parameters
- length int (default -100)
-
Represents the number of bytes, which should be read
-
Return Type
([byte[], int] | ReadTimedOutError) Content as a byte array and the number of bytes read or else a
socket:ReadTimedOutError
if the data can't be read from the client
Closes the client socket connection.
socket:Error? closeResult = socketClient->close();
-
Return Type
(Error?) A
socket:Error
if the client can't close the connection or else()
Shuts down any further reading from the socket.
socket:Error? result = socketClient->shutdownRead();
-
Return Type
(Error?) A
socket:Error
if the client can't be shut down to stop reading from the socket or else()