WebSocket

WebSocket.Close

Closes a WebSocket object returned by WebSocket.connect.

Syntax

WebSocket.Close(socket: WebSocket)

Arguments

NameTypeDescription
socketWebSocketWebSocket table returned by WebSocket.connect. The function expects this table to contain the connection state.

Description

Closes a WebSocket object returned by WebSocket.connect. The first argument must be a table. The function reads the object's connection state; when a live state exists and is not already destroyed or closed, it sets isClosed to true and sends an empty close frame frame with the stored WebSocket connection. It does not accept a close code or reason and returns no values.

Call it with 1 parameter(s): socket. The argument table explains which values are required and which ones only refine the behavior.

It does not return data. Treat the call as an action and handle errors around the call site when needed.

Example

Close a WebSocket object returned by WebSocket.connect.

local socket = WebSocket.connect("wss://example.com/socket")

socket:Close()