TsgcWebSocketProxyServer › Methods › WriteData
Sends a message to a single WebSocket client on the proxy identified by its connection GUID.
function WriteData(const aGuid, aMessage: string): Boolean;
| Name | Type | Description |
|---|---|---|
aGuid | const string | Identifier of the target connection as assigned by the proxy when the client handshake completed. |
aMessage | const string | Text payload to deliver to that client as a WebSocket text frame. |
True when a connection with the given GUID was located and the frame was handed to its socket; False when no matching active connection exists. (Boolean)
This overload looks up the WebSocket connection whose GUID matches aGuid and sends the text message to that single client on the browser-facing side of the tunnel. The GUID is the value exposed by TsgcWSConnection.Guid, typically captured in OnConnect and stored by the application. The paired upstream TCP link is not written to by this call; use it to push data from the proxy to the browser client without routing the bytes through the backend TCP server. Use Broadcast to reach every active WebSocket client in one call.
oServer.WriteData('guid', 'My First sgcWebSockets Message!.');
function WriteData(const aGuid: String; aStream: TStream; aSize: Integer = 0; const aStreaming: TwsStreaming = stmNone) : Boolean;
| Name | Type | Description |
|---|---|---|
aGuid | const String | Identifier of the target connection as assigned by the proxy when the client handshake completed. |
aStream | TStream | Source stream whose contents are sent to the client as a WebSocket binary frame. The caller remains the owner of the stream. |
aSize | Integer | Optional fragment size in bytes; when greater than zero the stream is split into multiple 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. |
True when a connection with the given GUID was located and the stream was handed to its socket; False when no matching active connection exists. (Boolean)
This overload targets a single WebSocket client on the browser-facing side of the proxy with a binary payload read from the supplied stream. The stream is consumed from its current position and the server does not take ownership, so the caller must keep it alive until WriteData returns. The upstream TCP connection associated with this GUID is not written to here; the bytes are delivered only to the WebSocket peer. Use aSize together with aStreaming when sending very large payloads that should be fragmented across multiple WebSocket frames.
oStream := TMemoryStream.Create;
try
oStream.LoadFromFile('payload.bin');
oServer.WriteData('guid', oStream);
finally
oStream.Free;
end;