WebSocket
Establish persistent WebSocket connections for real-time bidirectional messaging between a Roblox executor script and a remote endpoint.
A connection to your own server that stays open both ways. request is one shot, a WebSocket stays open. Good for a remote control panel, a live logger, or anything that needs to send you stuff instead of you polling it.
A full example
local socket = WebSocket.connect("ws://localhost:8080")
socket.OnMessage:Connect(function(message)
print("server said:", message)
end)
socket.OnClose:Connect(function()
warn("connection closed")
end)
socket:Send("hello")
-- ... later
if not socket.IsClosed then
socket:Close()
endCheck before sending
Sending on a closed socket errors. Check IsClosed, and when OnClose fires, stop.
OnMessage and OnClose are typed Signal instances; connect to them with :Connect(callback). They share the same surface as BindableEvent.Event, so any pattern you would use with a BindableEvent works here too.