WebSocket
The WebSocket library provides functions for creating WebSocket connections for real-time bidirectional communication.
The lowercase websocket global is an alias of the same read-only table.
The wss://your-server.example/socket URLs in these examples are
placeholders. Replace them with a WebSocket endpoint you control.
Overview
WebSockets allow you to:
- Establish persistent connections to servers
- Send and receive messages in real-time
Constructor
| Function | Description |
|---|---|
WebSocket.connect | Create a new WebSocket connection |
Properties
| Property | Type | Description |
|---|---|---|
OnMessage | VoltSignal | Fired when a message is received |
OnClose | VoltSignal | Fired when the connection closes |
IsClosed | boolean | Whether Close has been called |
Methods
| Method | Description |
|---|---|
WebSocket:Send | Send a text or binary message |
WebSocket:Close | Close the connection |