WebSocket class
This is a WebSocket client only, meaning you won't be able to create a server with this library.
The sUNC test explicitly checks for wss (secure) support.
The WebSocket class provides a lightweight interface for establishing and working with WebSocket connections. It allows scripts to send and receive messages over a persistent connection to a WebSocket server.
Constructor
Attempts to create a new connection to the provided URL. The URL must be a valid WebSocket server URL, typically starting with ws:// (unsecure) or wss:// (secure).
Parameters
| Parameter | Description |
|---|---|
url |
A WebSocket URL. |
Events
Signals that allow you handle events that occur during the WebSocket's lifetime, such as opening, receiving messages, or closing.
| Event | Description |
|---|---|
OnMessage(message: string): () |
Triggered when a message is received over the WebSocket connection. |
OnClose(): () |
Triggered when the WebSocket connection closes. |
Methods
| Method | Description |
|---|---|
Send(message: string): () |
Sends a message over the WebSocket connection. |
Close(): () |
Closes the WebSocket connection. |
Examples
Using the OnMessage event, and Send method
| Responding to incoming messages | |
|---|---|