Binary messaging
Send raw byte buffers without JSON structure using sendBinary(). Use this for custom protocols, efficient op streams, or payloads that do not fit the structured send() model.
sendBinary() contract
senderId
Yes
Must match the connecting user's userId
receiverIds
Yes
Array of target user IDs
buffer
Yes
Raw bytes (Uint8Array in JS, List<int> in Dart)
type
No
Frame type hint (default "binary")
Unlike send(), sendBinary() always requires receiverIds (array form).
When to use sendBinary vs send
Use send()
Use sendBinary()
Chat text, images, audio, docs
Custom binary protocol
JSON-serializable data
Game state, CRDT ops, compressed streams
Automatic chunking of structured payloads
Low-level framed bytes you parse yourself
Both methods chunk large buffers automatically.
Receiving binary
Binary frames arrive in onMessage. Inspect metadata.type and use payload.raw() when the body is not JSON:
Language guides
JavaScript / TypeScript
Dart / Flutter
Related topics
Last updated