AcediaDocumentation

WebSocket object

Methods and events returned by WebSocket.connect.

Methods

MemberType / signatureMeaning
SendSend(message: string): booleanAttempts to send message bytes; returns whether the send was accepted.
CloseClose(): ()Closes the socket and dispatches close notification.

Lowercase send and close aliases are available. The current Send wrapper has no separate binary-mode parameter.

Events

OnMessage and OnClose expose Connect(callback), Once(callback) and Wait(), with lowercase aliases. OnMessage delivers message strings. OnClose notifies closure. Returned connections expose Connected and Disconnect().

OnMessage:Wait() returns a message string when one arrives; it can return true when the socket closes instead. OnClose:Wait() yields until closure and returns true. Inspect the return type rather than assuming every wait result is a message.

local function openSocket(url)
    local socket = WebSocket.connect(url)
    socket.OnMessage:Connect(function(message) print(message) end)
    socket.OnClose:Once(function() print("Closed") end)
    return socket
end

Disconnect handlers and close the socket when finished. A connection does not survive a teleport.

On this page