TsgcTCPClient › Events › OnMessage
Fires when raw bytes received from the TCP server can be surfaced as text.
property OnMessage: TsgcWSMessageEvent;
// TsgcWSMessageEvent = procedure(Connection: TsgcWSConnection; const Text: string) of object
—
Unlike the WebSocket client, TsgcTCPClient does not negotiate a handshake and does not receive framed messages, so OnMessage delivers the raw bytes that arrived on the TCP socket converted to a string. When TCPEndOfFrameScanBuffer is eofScanNone every read is surfaced as it arrives; when it is eofScanLatestBytes or eofScanAllBytes the buffer is split on the TCPEndOfFrame delimiter and one event is raised per logical frame. The Text parameter carries the UTF-8 decoded payload; use OnBinary instead if the server sends non-textual data. By default NotifyEvents is neAsynchronous, so the handler runs in the context of the main thread and it is safe to update UI controls directly; switch to neNoSync if the client receives a high volume of data and you prefer to handle synchronization yourself.
procedure OnMessage(Connection: TsgcWSConnection; const Text: string);
begin
ShowMessage('Received from TCP server: ' + Text);
end;