TsgcWebSocketLoadBalancerServerMethods › Broadcast

Broadcast Method

Fans a WebSocket message out across every backup server in the cluster, optionally filtered by channel, protocol, or connection GUID list.

Overloads

Overload 1

Syntax

procedure Broadcast(const aMessage: string; const aChannel: string = ''; const aProtocol: string = ''; const Exclude: String = ''; const Include: String = '');

Parameters

NameTypeDescription
aMessageconst stringText payload delivered to each matching client as a WebSocket text frame.
aChannelconst stringWhen non-empty, the message is sent only to clients subscribed to the given channel.
aProtocolconst stringWhen non-empty, the message is sent only to clients using the given WebSocket sub-protocol.
Excludeconst StringComma-separated list of connection GUIDs that must be skipped by this broadcast.
Includeconst StringComma-separated list of connection GUIDs restricting the broadcast to that subset; ignored when empty.

Remarks

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.

Example


oServer.Broadcast('Hello From Server');

Overload 2

Syntax

procedure Broadcast(aStream: TStream; const aChannel: string = ''; const aProtocol: string = ''; const Exclude: String = ''; const Include: String = ''; const aSize: Integer = 0; const aStreaming: TwsStreaming = stmNone);

Parameters

NameTypeDescription
aStreamTStreamSource stream whose contents are delivered to each matching client as a WebSocket binary frame. The caller remains the owner of the stream.
aChannelconst stringWhen non-empty, the message is sent only to clients subscribed to the given channel.
aProtocolconst stringWhen non-empty, the message is sent only to clients using the given WebSocket sub-protocol.
Excludeconst StringComma-separated list of connection GUIDs that must be skipped by this broadcast.
Includeconst StringComma-separated list of connection GUIDs restricting the broadcast to that subset; ignored when empty.
aSizeconst IntegerOptional 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.
aStreamingconst TwsStreamingStreaming mode for fragmented transmission (stmNone, stmStart, stmContinue, stmFinish). Defaults to stmNone, which sends a complete standalone message.

Remarks

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.

Example


oStream := TMemoryStream.Create;
try
  oStream.LoadFromFile('payload.bin');
  oServer.Broadcast(oStream);
finally
  oStream.Free;
end;

Back to Methods