TsgcWebSocketServer › Methods › Broadcast
Sends the same message to all connected clients, optionally filtered by channel, protocol, or connection GUID list.
public void Broadcast(string aMessage, string aChannel = '', string aProtocol = '', string Exclude = '', string Include = '');
| Name | Type | Description |
|---|---|---|
aMessage | const string | Text payload delivered to each matching client as a WebSocket text frame. |
aChannel | const string | When non-empty, the message is sent only to clients subscribed to the given channel. |
aProtocol | const string | When non-empty, the message is sent only to clients using the given WebSocket sub-protocol. |
Exclude | const String | Comma-separated list of connection GUIDs that must be skipped by this broadcast. |
Include | const String | Comma-separated list of connection GUIDs restricting the broadcast to that subset; ignored when empty. |
This overload sends a text frame to every active connection that matches the supplied filters. Filters are combined with AND semantics: a connection receives the message only when it satisfies every non-empty filter, and is never reached when its GUID appears in Exclude. When LoadBalancer is enabled the call is forwarded across the cluster so remote nodes also deliver the message to their local clients. The call runs on the caller's thread and returns once the frames are handed to each socket; per-connection write errors are reported through OnException without aborting the broadcast.
public void Broadcast(TStream aStream, string aChannel = '', string aProtocol = '', string Exclude = '', string Include = '', int aSize = 0, TwsStreaming aStreaming = stmNone);
| Name | Type | Description |
|---|---|---|
aStream | TStream | Source stream whose contents are delivered to each matching client as a WebSocket binary frame. The caller remains the owner of the stream. |
aChannel | const string | When non-empty, the message is sent only to clients subscribed to the given channel. |
aProtocol | const string | When non-empty, the message is sent only to clients using the given WebSocket sub-protocol. |
Exclude | const String | Comma-separated list of connection GUIDs that must be skipped by this broadcast. |
Include | const String | Comma-separated list of connection GUIDs restricting the broadcast to that subset; ignored when empty. |
aSize | const Integer | Optional fragment size in bytes; when greater than zero each client receives the stream split into fragments of this size. Use 0 (the default) to send the whole stream as a single frame. |
aStreaming | const TwsStreaming | Streaming mode for fragmented transmission (stmNone, stmStart, stmContinue, stmFinish). Defaults to stmNone, which sends a complete standalone message. |
This overload broadcasts the stream contents as a binary frame to every connection that passes the channel, protocol, Include and Exclude filters. The stream is read from its current position; the server does not take ownership, so the caller must keep the stream alive until Broadcast returns. When LoadBalancer is enabled the binary payload is forwarded to other nodes so they can re-deliver it to their local clients. Use aSize together with aStreaming to stream very large payloads as multiple WebSocket fragments instead of one oversized frame.