World Executor · Roblox VM

WebSocket

Establish persistent WebSocket connections for real-time bidirectional messaging between a Roblox executor script and a remote endpoint.

Overview

A persistent, two-way connection to a server of your own. Where request is one shot, a WebSocket stays open, which is what you want for a remote control panel, a live logger, or anything that has to push to you rather than be polled.

A full session
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()
end

Guard the send

Sending on a closed socket errors. Check IsClosed, and treat OnClose as the signal to stop rather than as a notification.

Overview

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.

Constructor

Events

Properties

Methods