Skip to content

websocket

Asynchronous WebSocket client, off the game thread. Needs the websocket capability, so websocket is nil unless it was granted. wss only.

websocket.connect(url: string, handlers: table): socket|nil

Argument Type Description
url string wss URL.
handlers table { open?, message?(text), close?(code, reason), error?(message) }.

Opens a connection. Returns the socket, or nil when the URL is refused or the per-script limit is reached.

The value websocket.connect returns.

socket:send(text: string): boolean

Sends a text frame. Returns whether it was sent.

socket:close([code: integer])

Closes the connection with an optional status code.