# websocket

Asynchronous WebSocket client, off the game thread. Needs the `websocket` capability, so `websocket` is `nil` unless it was granted. wss only.

#### websocket.connect

`websocket.connect(url: string, handlers: table)`: socket|nil

Argument | Type | Description
-------- | ---- | -----------
  **url** | string | wss URL.
  **handlers** | table | `{ open?, message?(text), close?(code, reason), error?(message) }`.

Opens a connection. Returns the socket, or nil when the URL is refused or the per-script limit is reached.

## socket

The value `websocket.connect` returns.

#### socket:send

`socket:send(text: string)`: boolean

Sends a text frame. Returns whether it was sent.

#### socket:close

`socket:close([code: integer])`

Closes the connection with an optional status code.