WebSocket Protocol
The WebSocket Protocol enables two-way communication between a client running code in a controlled environment to a remote host that has opted-in to communications from that code. The security model used for this is the origin based security model commonly used by web browsers. The protocol consists of an opening handshake followed by basic message framing, layered over TCP. The goal of this technology is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections.

To use WebSocket, add the following line to your script:

Connect to host with given protocol (ws
or wss
) to URL and port with optional sub-protocol.

Sends message to server.

Closes the connection to the server.

Callback called when WebSocket is connected.

Callback called when a new message is received by the WebSocket.

Callback called when an error occurs on the WebSocket.

Callback called when the WebSocket is closed.

Ping is used to keep a WebSocket connection alive.
Portions of this topic are reprinted under permission of the Lua WebSocket Protocol license.