Clients - socket : Client

Represents socket client and related remote functions.

Constructor

__init

(ClientConfig? clientConfig)

Remote Methods

Fields

  • remotePort int 0
  • the remote port number to which this socket is connected

  • localPort int 0
  • the local port number to which this socket is bound

  • remoteAddress string ()
  • the remote IP address string in textual presentation to which the socket is connected

  • localAddress string ()
  • the local IP address string in textual presentation to which the socket is bound

  • id int 0
  • a unique identifier to identify each client

write

(byte content)

returns int | Error

Writes given data to the client socket.

Parameters

  • content byte
    • the content that wish to send to the client socket

  • Return Type

    (int | Error)
    • number of bytes got written or an error if encounters an error while writing

read

(int length)

returns [byte, int] | ReadTimedOutError

Reads data from the client socket. If the data has the specified length, then wait until that number of bytes are received from the client. Else, return 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.

Parameters

  • length int - -100
    • Positive integer. 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 an error if encounters an error while reading

close

()

returns Error?

Closes the client socket connection.

  • Return Type

    (Error?)
    • an error if encounters an error while closing the connection or returns nil otherwise

shutdownRead

()

returns Error?

Shutdowns the further read from socket.

  • Return Type

    (Error?)
  • an error if encounters an error while shutdown the read from socket or returns nil otherwise

shutdownWrite

()

returns Error?

Shutdowns the further write from socket.

  • Return Type

    (Error?)
  • an error if encounters an error while shutdown the write from socket or returns nil otherwise