Skip to content

WebSocket Client Class Pattern

The WebSocket Client Class Pattern establishes a connection to an endpoint hosting a WebSocket server.

import WebSocketClient from "embedded:network/ws/client";

Creates a new WebSocketClient object instance.

WebSocketClient(options)

options

socket - A TCP class constructor options object.

host - The remote hostname to connect to.

port (optional) - The remote port number to connect to.

protocol (optional) - The WebSocket sub-protocol as a string.

Returns the current message.

Sends a message.

Initiates a clean close of the WebSocket connection.

WebSocket Client Class Pattern