ReferenceNetwork

socket signal:connect

Subscribes a callback to a socket’s OnMessage or OnClose signal. The returned connection can be disconnected to stop future deliveries. OnMessage supplies the message bytes; OnClose indicates closure.

Syntax

socket.OnMessage:connect(callback: function) -> Connection

Parameters

ParameterTypeDescription
callbackfunctionHandler called on signal delivery.

Returns

TypeDescription
ConnectionListener connection.

Description

These methods operate on the socket’s signal, not on the socket itself. Do not wait for a message that has already arrived before the listener was installed.

Example

local socket = WebSocket.connect("wss://your-server.example/socket")
local connection = socket.OnMessage:connect(function(message)
    print(message)
end)
connection:Disconnect()

These are Game executor contracts. Check build requirements and session lifetimes before using them.