WebSocket.connect
Opens a WebSocket connection and returns a socket object.
Syntax
WebSocket.connect(url: string) -> WebSocket
Also available as
WebSocket.ConnectWebSocket.newWebsocket.ConnectWebsocket.connectWebsocket.newwebsocket.Connectwebsocket.connectwebsocket.new
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | WebSocket endpoint. |
Returns
| Type | Description |
|---|---|
WebSocket | Connected socket with message and close signals. |
Description
Use ws:// or wss://; secure connections validate the remote certificate. The call yields while connecting and raises an error when connection setup fails. The returned object has Send and Close methods, OnMessage and OnClose signals, and an IsClosed state. OnMessage delivers message data; register handlers before sending messages that expect a response.
A socket belongs to the current game session. Close it when the consumer is finished, and handle remote closure rather than assuming the connection remains available indefinitely.
Example
local socket = WebSocket.connect("wss://your-server.example/socket")
socket.OnMessage:connect(function(message)
print(message)
end)
socket.OnClose:connect(function()
print("Socket closed")
end)
socket:Send("hello")
Notes
- Replace the example endpoint with a server you control. Connection limits and message-size bounds apply.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
