AcediaDocumentation

WebSocket.connect

Connects to a WebSocket server.

Yields until the handshake completes. The returned object exposes Send, Close, OnMessage and OnClose. Connections and event handlers belong to the current game session.

The handshake carries the executor User-Agent that request sends. Unlike the HTTP calls it adds no fingerprint or session headers, so a server identifies the connection by the agent alone.

WebSocket.connect(url: string): WebSocket

Parameters

ParameterTypeDescription
urlstringws:// or wss:// URL with a host.

See WebSocket for the object’s members.

Example

local function connectToServer(url)
    local socket = WebSocket.connect(url)
    socket.OnMessage:Connect(function(message) print(message) end)
    return socket
end

Example output

hello from the server

One line per text frame the server pushes; the actual payload is whatever the connected endpoint sends.

Errors: Invalid URL schemes, missing hosts and failed handshakes raise errors.

Aliases: WebSocket.Connect, websocket.connect, websocket.Connect.

On this page