WebSocketConnection
Represents an active WebSocketConnection connection.
This object is returned by websocket.connect
upon a successful connection. It allows sending messages and listening for incoming messages and closure events.
Properties
OnMessage
This item is read only and cannot be modified. Read OnlyAn RBXScriptSignal that fires when a message is received from the WebSocketConnection server.
Connecting
local webSocket = websocket.connect("wss://example.com")
if webSocket then
webSocket.OnMessage:Connect(function(message)
print("Received message:", message)
end)
end
OnClose
This item is read only and cannot be modified. Read OnlyWebSocketConnection.OnClose:
RBXScriptSignal
An RBXScriptSignal (effectively BindableEvent.Event
) that fires when the WebSocketConnection connection is closed, either initiated by the server, the client (:Close()
), or due to an error.
Connecting
local webSocket = websocket.connect("wss://example.com")
if webSocket then
webSocket.OnClose:Connect(function()
print("WebSocketConnection connection closed")
end)
end
URL
This item is read only and cannot be modified. Read OnlyWebSocketConnection.URL:
string
The URL of the websocket connection.
Functions
Send
WebSocketConnection:
Send
(
message:
string
--
The message to send.
) →
(
)
Sends a string message over the WebSocketConnection connection.
If the connection is not currently open (e.g., it's connecting, closed, or closing), this method does nothing.
Close
WebSocketConnection:
Close
(
) →
(
)
Closes the WebSocketConnection connection.
This will trigger the OnClose
event asynchronously. If the connection is already closed or closing, this method does nothing.