TsgcWSPServer_sgcMethods › Broadcast

Broadcast Method

Broadcasts a text or stream payload to all connected clients, optionally filtered by channel.

Overloads

Overload 1

Syntax

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

Parameters

NameTypeDescription
aMessagestringText payload wrapped in the sgc envelope and delivered to recipients through OnMessage.
aChannelstringOptional channel filter. When supplied, only clients subscribed to that channel receive the payload; leave empty to reach every connection.
ExcludeStringSemicolon-separated list of connection Guids that must not receive the broadcast.
IncludeStringSemicolon-separated list of connection Guids that the broadcast is restricted to, overriding the channel filter.

Remarks

Text overload. Sends a method=message envelope to the selected recipients. When QoS is Level 1 or Level 2 the server stores the message in the pending list and waits for per-connection acknowledgements, resending if necessary; with QoS Level 0 the message is transmitted once without tracking.

Example

oProtocol.Broadcast('hello everyone');
oProtocol.Broadcast('channel update', 'news');

Overload 2

Syntax

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

Parameters

NameTypeDescription
aStreamTStreamBinary payload sent as-is on the WebSocket; recipients receive it through OnBinary.
aChannelstringOptional channel filter. When supplied, only clients subscribed to that channel receive the frame.
ExcludeStringSemicolon-separated list of connection Guids that must not receive the frame.
IncludeStringSemicolon-separated list of connection Guids that the frame is restricted to.
aSizeIntegerChunk size in bytes when the payload is fragmented; pass 0 to send the stream as a single frame.
aStreamingTwsStreamingStreaming strategy (stmNone, stmFragmented, stmCustom) used to chop the stream into frames.

Remarks

Binary overload. Dispatches the stream directly to selected recipients without wrapping it in the sgc JSON envelope, so clients see a raw binary frame. Unlike the text overload this path does not use the QoS pending list; delivery is best-effort on the underlying WebSocket transport.

Example

oStream := TFileStream.Create('image.png', fmOpenRead);
try
  oProtocol.Broadcast(oStream, 'news');
finally
  oStream.Free;
end;

Back to Methods