---
title: "WebSocketObject.Send"
description: "Sends a text or binary message over an open WebSocket."
---

```lua
socket:Send(data: string, binary: boolean? = false): (boolean, string?)
```

---

## Aliases

- `WebSocketObject.send`

---

## Arguments

<ParamField body="data" type="string" required>
  The input bytes as a binary-safe Luau string.
</ParamField>

<ParamField body="binary" type="boolean" default={"false"}>
  Whether to send a binary frame. Invalid UTF-8 text is automatically sent as binary.
</ParamField>

---

## Returns

<ResponseField name="success" type="boolean">
  True when the native send succeeds.
</ResponseField>

<ResponseField name="error" type="string?">
  A diagnostic when the native send returns false.
</ResponseField>

Start a WebSocket server on port 8765 before running the example. Payloads over 16 MiB return false, diagnostic. Invalid UTF-8 text is sent as binary. Type errors can raise. Supports socket.Send(data, binary) as well as colon calls.

**Related types:** [WebSocket types & behavior](/reference/websocket/types).

---

## Example

```lua
local ok, socket = pcall(WebSocket.connect, "ws://127.0.0.1:8765")
if not ok then warn(socket); return end
local sent, err = socket:Send("hello", false)
print(sent, err)
socket:Close()
```
