WebSocket: Close Synchronous
End a WebSocket session and release its connection slot when you no longer need it. Local OnClose listeners are notified as closing begins.
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
()No values.
Usage notes
Calling Close again does not publish another OnClose event. Accepted outgoing frames get a short chance to finish, but closure does not guarantee delivery.
The connection slot is released by background cleanup.
Limits
| Resource | Limit | What happens |
|---|---|---|
| Graceful close | 10 seconds | The transport tries to drain accepted outgoing frames before closing. If it cannot finish within the deadline, it shuts down and discards remaining queued data. |
The local OnClose notification is not an acknowledgment from the server. The background close can still be in progress after the callback and Close have returned.
Example
Luau
local socket = WebSocket.connect("wss://echo.websocket.events")
socket.OnClose:Connect(function() print("Closed") end)
socket:Send("goodbye")
socket:Close()