WebSocket:Close Synchronous

Close this WebSocket and notify its OnClose listeners. Use it to release a connection when the script no longer needs to exchange messages.

Syntax
Luau
WebSocket:Close() -> ()

Parameters

Call this method with a WebSocket receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

This function takes no arguments.

Returns

()

This function returns no values.

Usage notes

Kawaii publishes the local OnClose event, marks the socket closed, and begins closing the transport. Calling Close again does not publish a second close event.

Example

Example
Luau
-- Requires an echo server you control at this address.
local socket = WebSocket.connect("ws://127.0.0.1:8765")
local closed = socket.OnClose:Connect(function()
    print("Socket closed")
end)
socket:Close()
print(socket.IsClosed) -- true
closed:Disconnect()
Kawaii documentation