WebSocket.connect
WebSocket
The WebSocket class provides a simple interface for sending and receiving data over a WebSocket connection.
Constructor - WebSocket.connect
function WebSocket.connect(url: string): WebSocketWebSocket Methods
Method
Description
Send(message: string): ()
Sends a message over the WebSocket connection.
Close(): ()
Closes the WebSocket connection.
WebSocket Events
Event
Description
OnMessage(message: string): ()
Triggered when a message is received over the WebSocket connection.
OnClose(): ()
Triggered when the WebSocket connection closes.
Example - WebSocket.connect
WebSocket.connectlocal ws = WebSocket.connect("ws://echo.websocket.events")
print(ws) -- Output: WebSocketExample - OnMessage, Send
OnMessage, Sendlocal ws = WebSocket.connect("ws://echo.websocket.events")
ws.OnMessage:Connect(function(message)
print(message)
end)
ws:Send("Hello") -- Output: HelloExample - OnClose, Close
OnClose, Closelocal ws = WebSocket.connect("ws://echo.websocket.events")
ws.OnClose:Connect(function()
print("Closed")
end)
ws:Close() -- Output: ClosedLast updated