Clients - http : WebSocketClient

Represents a WebSocket client endpoint.

Constructor

__init

(string url, WebSocketClientConfiguration? config)

  • url string
  • URL of the target service

Remote Methods

pushText

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

pushBinary

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

ping

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

pong

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

close

Closes the connection.

ready

Calls when the endpoint is ready to receive messages. It can be called only once per endpoint. For the WebSocketListener, it can be called only in the upgrade or onOpen resources.

Methods

Initializes the endpoint.

Sets a connection-related attribute.

Gets connection-related attributes if any.

Removes connection related attribute if any.

Gives the connection id associated with this connection.

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

Gives the secured status of the connection.

Gives the open or closed status of the connection.

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

pushText

(string | json | xml | boolean | int | float | byte | byte[] data, boolean finalFrame)

returns WebSocketError?

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

Parameters

  • data string | json | xml | boolean | int | float | byte | byte[]
  • Data to be sent. If it is a byte[], it is converted to a UTF-8 string for sending

  • finalFrame boolean (default true)
  • Set to true if this is a final frame of a (long) message

  • Return Type

    (WebSocketError?)
  • An error if an error occurs when sending

pushBinary

(byte[] data, boolean finalFrame)

returns WebSocketError?

Pushes 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

  • finalFrame boolean (default true)
  • Set to true if this is a final frame of a (long) message

  • Return Type

    (WebSocketError?)
  • An error if an error occurs when sending

ping

(byte[] data)

returns WebSocketError?

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

    (WebSocketError?)
  • An error if an error occurs when sending

pong

(byte[] data)

returns WebSocketError?

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

Parameters

  • data byte[]
  • Binary data to be sent

  • Return Type

    (WebSocketError?)
  • An error if an error occurs when sending

close

(int? statusCode, string? reason, int timeoutInSeconds)

returns WebSocketError?

Closes the connection.

Parameters

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

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

  • timeoutInSeconds int (default 60)
  • Time to wait 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

    (WebSocketError?)
  • An error if an error occurs while closing the WebSocket connection

ready

()

returns WebSocketError?

Calls when the endpoint is ready to receive messages. It can be called only once per endpoint. For the WebSocketListener, it can be called only in the upgrade or onOpen resources.

  • Return Type

    (WebSocketError?)
  • an error if an error occurs while checking the connection state

initEndpoint

Initializes the endpoint.

setAttribute

Sets a connection-related attribute.

Parameters

  • key string
  • The key, which identifies the attribute

  • value any
  • The value of the attribute

getAttribute

(string key)

returns any

Gets connection-related attributes if any.

Parameters

  • key string
  • The key to identify the attribute

  • Return Type

    (any)
  • The attribute related to the given key or nil

removeAttribute

(string key)

returns any

Removes connection related attribute if any.

Parameters

  • key string
  • The key to identify the attribute

  • Return Type

    (any)
  • The attribute related to the given key or nil

getConnectionId

()

returns string

Gives the connection id associated with this connection.

  • Return Type

    (string)
  • The unique ID associated with the connection

getNegotiatedSubProtocol

()

returns string?

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

()

returns boolean

Gives the secured status of the connection.

  • Return Type

    (boolean)
  • true if the connection is secure

isOpen

()

returns boolean

Gives the open or closed status of the connection.

  • Return Type

    (boolean)
  • true if the connection is open

getHttpResponse

()

returns Response?

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

  • Return Type

    (Response?)
  • The HTTP response received from the client handshake request