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

FunctionDescription
WebSocket.connectCreate a new WebSocket connection

Properties

PropertyTypeDescription
OnMessageVoltSignalFired when a message is received
OnCloseVoltSignalFired when the connection closes
IsClosedbooleanWhether Close has been called

Methods

MethodDescription
WebSocket:SendSend a text or binary message
WebSocket:CloseClose the connection