WebSocket.connect(url: string) → WebSocket yields
Open a WebSocket connection. URL must start with
ws:// or wss://. Returns a wrapper table with methods and event signals.aliasesWebSocket.Connect, WebSocket.new, WebSocket.New
lua
local ws = WebSocket.connect("wss://echo.websocket.org")
ws:Send(message: string)
Send a message frame to the server.
lua
ws:Send("hello")
ws:Close()
Close the connection.
lua
ws:Close()
ws.OnMessage — RBXScriptSignal
Fires with each inbound message. Underlying
WebSocketClient.MessageReceived.
lua
ws.OnMessage:Connect(function(msg) print("got:", msg) end)
ws.OnClose — RBXScriptSignal
Fires once when the connection closes. Underlying
WebSocketClient.Closed.
lua
ws.OnClose:Connect(function() print("closed") end)
lua
local ws = WebSocket.connect("wss://echo.websocket.org") ws.OnMessage:Connect(function(msg) print("got:", msg) end) ws.OnClose:Connect(function() print("closed") end) ws:Send("hello")