socket.OnMessage
Signals fired for incoming messages and connection close.
Syntax
socket.OnMessage
Parameters
This function takes no parameters.
Returns
| Type | Description |
|---|---|
RBXScriptSignal | The message and close signals exposed by the socket. |
Description
OnMessage and OnClose are RBXScriptSignals. OnMessage fires for every incoming text or binary message; OnClose fires once when the connection ends.
Lowercase onMessage and onClose aliases point at the same signals.
Example
local ws = WebSocket.open("wss://echo.websocket.events")
ws.OnMessage:Connect(function(message)
print(message)
end)
ws.OnClose:Connect(function()
print("closed")
end)
Notes
- Aliases:
socket.onMessage,socket.OnClose,socket.onClose. - Keep message callbacks short; they run on the module's networking thread.
- Connect a callback before sending if you expect an immediate reply.