TsgcWebSocketLoadBalancerServer › Methods › Broadcast
Fans a WebSocket message out across every backup server in the cluster, optionally filtered by channel, protocol, or connection GUID list.
procedure Broadcast(const aMessage: string; const aChannel: string = ''; const aProtocol: string = ''; const Exclude: String = ''; const Include: String = '');
| 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 through the load balancer so that every registered backup server re-delivers it to its own locally connected WebSocket clients. 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. Pure HTTP/HTTP2 requests are ignored because Broadcast only targets clients that completed the WebSocket handshake. The load balancer forwards the payload to each backup node in turn; per-connection write errors are reported through OnException without aborting the broadcast. The call runs on the caller's thread and returns once the frames are handed to each link towards the backup servers.
oServer.Broadcast('Hello From Server');
procedure Broadcast(aStream: TStream; const aChannel: string = ''; const aProtocol: string = ''; const Exclude: String = ''; const Include: String = ''; const aSize: Integer = 0; const aStreaming: TwsStreaming = 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 through the load balancer, which forwards the payload to every registered backup server so they can re-deliver it to their local WebSocket clients. The stream is read from its current position; the load balancer does not take ownership, so the caller must keep the stream alive until Broadcast returns. The channel, protocol, Include and Exclude filters are evaluated on each backup node as it dispatches the frame to its own connections. Use aSize together with aStreaming to stream very large payloads as multiple WebSocket fragments instead of one oversized frame.
oStream := TMemoryStream.Create;
try
oStream.LoadFromFile('payload.bin');
oServer.Broadcast(oStream);
finally
oStream.Free;
end;