Parameters
Returns
AWebSocket socket object with this surface:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
WebSocket.connect(url: string): WebSocket
| Parameter | Type | Description |
|---|---|---|
url | string | The server URL. Starts with ws:// or wss://. |
WebSocket socket object with this surface:
| Member | Kind | Description |
|---|---|---|
Send(message: string, is_binary: boolean?) | method | Sends data to the server. is_binary is optional and defaults to false. |
Close() | method | Closes the connection. |
OnMessage | event | Fires when the server sends a message. The handler gets the message string. |
OnClose | event | Fires when the connection closes. |
local ws = WebSocket.connect("wss://echo.websocket.events")
ws.OnMessage:Connect(function(message)
print(message)
end)
ws:Send("Hello") -- Output: Hello
local ws = WebSocket.connect("wss://echo.websocket.events")
ws.OnClose:Connect(function()
print("Closed")
end)
ws:Close() -- Output: Closed