TsgcWSPServer_sgc › Methods › Broadcast
Broadcasts a text or stream payload to all connected clients, optionally filtered by channel.
procedure Broadcast(aMessage: string; aChannel: string = ''; Exclude: String = ''; Include: String = '');
| Name | Type | Description |
|---|---|---|
aMessage | string | Text payload wrapped in the sgc envelope and delivered to recipients through OnMessage. |
aChannel | string | Optional channel filter. When supplied, only clients subscribed to that channel receive the payload; leave empty to reach every connection. |
Exclude | String | Semicolon-separated list of connection Guids that must not receive the broadcast. |
Include | String | Semicolon-separated list of connection Guids that the broadcast is restricted to, overriding the channel filter. |
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.
oProtocol.Broadcast('hello everyone');
oProtocol.Broadcast('channel update', 'news');
procedure Broadcast(aStream: TStream; aChannel: string = ''; Exclude: String = ''; Include: String = ''; aSize: Integer = 0; aStreaming: TwsStreaming = stmNone);
| Name | Type | Description |
|---|---|---|
aStream | TStream | Binary payload sent as-is on the WebSocket; recipients receive it through OnBinary. |
aChannel | string | Optional channel filter. When supplied, only clients subscribed to that channel receive the frame. |
Exclude | String | Semicolon-separated list of connection Guids that must not receive the frame. |
Include | String | Semicolon-separated list of connection Guids that the frame is restricted to. |
aSize | Integer | Chunk size in bytes when the payload is fragmented; pass 0 to send the stream as a single frame. |
aStreaming | TwsStreaming | Streaming strategy (stmNone, stmFragmented, stmCustom) used to chop the stream into frames. |
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.
oStream := TFileStream.Create('image.png', fmOpenRead);
try
oProtocol.Broadcast(oStream, 'news');
finally
oStream.Free;
end;