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): WebSocketParameters
| Parameter | Type | Description |
|---|---|---|
url | string | ws:// 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
endExample output
hello from the serverOne 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.
