TsgcWSPServer_DatasetMethods › 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, independent from the internal dataset update channel. Use it for side-band notifications (status, presence, custom signalling) that should reach peers without going through the dataset sync path.

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. Useful to push attachments, images or protobuf payloads alongside the dataset sync.

Example

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

Back to Methods