Client: Client

Isolated

Represents a WebSocket synchronous client endpoint.

Constructor

Initializes the synchronous client when called.

init (string url, *ClientConfiguration config)
  • url string
  • URL of the target service

Remote Methods

writeTextMessage

Writes text messages to the connection.

writeBinaryMessage

Writes binary data to the connection.

ping

Pings the connection.

pong

Sends a pong message to the connection.

close

Closes the connection.

readTextMessage

Reads text messages in a synchronous manner

readBinaryMessage

Reads binary data in a synchronous manner

Methods

initEndpoint
setAttribute

Sets a connection-related attribute.

getAttribute

Gets connection-related attributes if any.

removeAttribute

Removes connection related attribute if any.

getConnectionId

Gives the connection id associated with this connection.

getNegotiatedSubProtocol

Gives the subprotocol if any that is negotiated with the client.

isSecure

Gives the secured status of the connection.

isOpen

Gives the open or closed status of the connection.

getHttpResponse

Gives the HTTP response if any received for the client handshake request.

writeTextMessage

function writeTextMessage(string data) returns Error?
Isolated Function
Remote Function

Writes text messages to the connection. If an error occurs while sending the text message to the connection, that message will be lost.

Parameters

Return Type

(Error?)

A websocket:Error if an error occurs when sending

writeBinaryMessage

function writeBinaryMessage(byte[ ] data) returns Error?
Isolated Function
Remote Function

Writes binary data to the connection. If an error occurs while sending the binary message to the connection, that message will be lost.

Parameters

  • data byte[ ]
  • Binary data to be sent

Return Type

(Error?)

A websocket:Error if an error occurs when sending

ping

function ping(byte[ ] data) returns Error?
Isolated Function
Remote Function

Pings the connection. If an error occurs while sending the ping frame to the server, that frame will be lost.

Parameters

  • data byte[ ]
  • Binary data to be sent

Return Type

(Error?)

A websocket:Error if an error occurs when sending

pong

function pong(byte[ ] data) returns Error?
Isolated Function
Remote Function

Sends a pong message to the connection. If an error occurs while sending the pong frame to the connection, that the frame will be lost.

Parameters

  • data byte[ ]
  • Binary data to be sent

Return Type

(Error?)

A websocket:Error if an error occurs when sending

close

function close(int? statusCode, string? reason, decimal timeout) returns Error?
Isolated Function
Remote Function

Closes the connection.

Parameters

  • statusCode int? (default 1000)
  • Status code for closing the connection

  • reason string? (default ())
  • Reason for closing the connection

  • timeout decimal (default 60)
  • Time to wait (in seconds) for the close frame to be received from the remote endpoint before closing the connection. If the timeout exceeds, then the connection is terminated even though a close frame is not received from the remote endpoint. If the value is < 0 (e.g., -1), then the connection waits until a close frame is received. If the WebSocket frame is received from the remote endpoint within the waiting period, the connection is terminated immediately.

Return Type

(Error?)

A websocket:Error if an error occurs while closing the WebSocket connection

readTextMessage

function readTextMessage() returns string | Error
Isolated Function
Remote Function

Reads text messages in a synchronous manner

Return Type

(string | Error)

The text data sent by the server or a websocket:Error if an error occurs when receiving

readBinaryMessage

function readBinaryMessage() returns byte[ ] | Error
Isolated Function
Remote Function

Reads binary data in a synchronous manner

Return Type

(byte[ ] | Error)

The binary data sent by the server or an websocket:Error if an error occurs when receiving

initEndpoint

function initEndpoint() returns Error?
Isolated Function

Return Type

(Error?)

setAttribute

function setAttribute(string key, string | int value)
Isolated Function

Sets a connection-related attribute.

Parameters

  • key string
  • The key, which identifies the attribute

  • value string | int
  • The value of the attribute

getAttribute

function getAttribute(string key) returns string | int?
Isolated Function

Gets connection-related attributes if any.

Parameters

  • key string
  • The key to identify the attribute

Return Type

(string | int?)

The attribute related to the given key or nil

removeAttribute

function removeAttribute(string key) returns string | int?
Isolated Function

Removes connection related attribute if any.

Parameters

  • key string
  • The key to identify the attribute

Return Type

(string | int?)

The attribute related to the given key or nil

getConnectionId

function getConnectionId() returns string
Isolated Function

Gives the connection id associated with this connection.

Return Type

(string)

The unique ID associated with the connection

getNegotiatedSubProtocol

function getNegotiatedSubProtocol() returns string?
Isolated Function

Gives the subprotocol if any that is negotiated with the client.

Return Type

(string?)

The subprotocol if any negotiated with the client or nil

isSecure

function isSecure() returns boolean
Isolated Function

Gives the secured status of the connection.

Return Type

(boolean)

true if the connection is secure

isOpen

function isOpen() returns boolean
Isolated Function

Gives the open or closed status of the connection.

Return Type

(boolean)

true if the connection is open

getHttpResponse

function getHttpResponse() returns Response?
Isolated Function

Gives the HTTP response if any received for the client handshake request.

Return Type

(Response?)

The HTTP response received from the client handshake request