> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket.Send

> Sends a Lua string with a WebSocket object returned by WebSocket.connect. The method expects the WebSocket table as the first argument and the message string as the second argument. It reads the object's connection state, raises "WebSocket state is missing" if that object is absent, returns without sending when the state is destroyed or closed, and calls curl_ws_send with CURLWS_TEXT by default or CURLWS_BINARY when the optional third argument is a boolean true. It returns no values and does not report the number of bytes sent.

Sends a Lua string with a WebSocket object returned by WebSocket.connect. The method expects the WebSocket table as the first argument and the message string as the second argument. It reads the object's connection state, raises "WebSocket state is missing" if that object is absent, returns without sending when the state is destroyed or closed, and calls curl\_ws\_send with CURLWS\_TEXT by default or CURLWS\_BINARY when the optional third argument is a boolean true. It returns no values and does not report the number of bytes sent.

## Syntax

```lua theme={null}
WebSocket.Send(socket: WebSocket, message: string, isBinary?: boolean)
```

## Arguments

| Name       | Type        | Required | Description                                                                                                                                        |
| ---------- | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `socket`   | `WebSocket` | Yes      | WebSocket table returned by WebSocket.connect. Send is resolved from the WebSocket object methods, so the documented call form is socket:Send(..). |
| `message`  | `string`    | Yes      | Lua string payload passed to curl\_ws\_send with its explicit byte length.                                                                         |
| `isBinary` | `boolean`   | No       | When this argument is present and true, Send uses CURLWS\_BINARY. Otherwise it uses CURLWS\_TEXT.                                                  |

## Example

Send text or binary data through a WebSocket object returned by WebSocket.connect.

```lua theme={null}
local socket = WebSocket.connect("wss://example.com/socket")

socket:Send("hello")
socket:Send(string.char(0, 1, 2, 3), true)
```
