Skip to main content

Server Broadcasting

Broadcasting allows you to send updates to multiple WebSocket connections simultaneously, enabling real-time features like live notifications, chat systems, and collaborative applications.

Basic Broadcasting

Broadcast to All Connections

Send to Specific Connection

Real-Time Applications

Chat System

Live Notifications

Live Dashboard Updates

Selective Broadcasting

Room-Based Broadcasting

Permission-Based Broadcasting

Geographic Broadcasting

Advanced Broadcasting Patterns

Batch Broadcasting

Event-Driven Broadcasting

Rate-Limited Broadcasting

JSON Channel Broadcasting

When you need to send structured data instead of HTML, use the JSON helpers. Each message carries an identifier, channel name, payload, and optional metadata that the client receives untouched.
Register listeners with wsx.onJson() on the client or listen for the wsx:json browser event to respond declaratively.

Binary Stream Broadcasting

Binary helpers let you pipe raw media or file chunks through the same WebSocket connection. Frames are prefixed with metadata so receivers know how to interpret the bytes.
On the client, pair wsx.onStream() with wsx.sendStream() to move data in both directions. Stream payloads arrive as Uint8Array views; convert them to Buffer, Blob, or other formats as needed before processing.

Connection Management

Connection Tracking

Performance Considerations

Efficient Broadcasting

Memory Management

Best Practices

  1. Filter Connections: Only broadcast to relevant connections
  2. Batch Updates: Group multiple updates when possible
  3. Rate Limiting: Prevent spam and server overload
  4. Connection Management: Track and clean up connections
  5. Error Handling: Handle broadcasting errors gracefully
  6. Performance: Optimize for high-frequency broadcasts
  7. Security: Validate permissions before broadcasting

Next Steps