WebSocket object
Methods and events returned by WebSocket.connect.
Methods
| Member | Type / signature | Meaning |
|---|---|---|
Send | Send(message: string): boolean | Attempts to send message bytes; returns whether the send was accepted. |
Close | Close(): () | Closes the socket and dispatches close notification. |
Lowercase send and close aliases are available. The current Send wrapper has no separate binary-mode parameter.
Events
OnMessage and OnClose expose Connect(callback), Once(callback) and Wait(), with lowercase aliases. OnMessage delivers message strings. OnClose notifies closure. Returned connections expose Connected and Disconnect().
OnMessage:Wait() returns a message string when one arrives; it can return true when the socket closes instead. OnClose:Wait() yields until closure and returns true. Inspect the return type rather than assuming every wait result is a message.
local function openSocket(url)
local socket = WebSocket.connect(url)
socket.OnMessage:Connect(function(message) print(message) end)
socket.OnClose:Once(function() print("Closed") end)
return socket
endDisconnect handlers and close the socket when finished. A connection does not survive a teleport.
