---
title: "WebSocket types & behavior"
description: "Object fields, option tables, and behavior for WebSocket."
---


## Socket fields and methods

| Member | Signature / type | Behavior |
| --- | --- | --- |
| Send / send | socket:Send(data: string, binary: boolean? = false): (boolean, string?) | Returns true, or false plus native diagnostic |
| Close / close | socket:Close(): () | Closes once, stops the pump, and fires OnClose |
| OnMessage / onMessage | RBXScriptSignal | Callback(data: string, binary: boolean) |
| OnClose / onClose | RBXScriptSignal | Callback(reason: string?) |

Send supports both socket:Send(data, binary) and socket.Send(data, binary). Maximum send payload is 16 MiB. Invalid UTF-8 in a text payload is automatically sent as binary. Native argument type errors can still raise; a false result is not the only error path.

OnMessage/OnClose are BindableEvent-backed signals. Native snapshots are polled on Heartbeat. Close is idempotent; local Close usually fires a nil reason. The backing events are destroyed two heartbeat frames later so deferred listeners can receive close notifications. Retain the socket while in use; its weak-reference pump closes abandoned sockets.

WebSocket.Version is 2.0-rewrite. No public open/poll transport-token functions, reconnect option, timeout option, headers option, or connection-state property are registered by this facade. connect/Connect/new/New exist in both WebSocket and websocket namespaces.
