TsgcTCPClient › Events › OnBinary
Fires when raw bytes have been received from the TCP server.
property OnBinary: TsgcWSBinaryEvent;
// TsgcWSBinaryEvent = procedure(Connection: TsgcWSConnection; const Data: TMemoryStream) of object
—
Because TsgcTCPClient speaks raw TCP without a WebSocket handshake there are no typed frames, so OnBinary delivers the bytes exactly as they were read from the socket. When TCPEndOfFrameScanBuffer is eofScanNone every socket read triggers the event with whatever has been buffered; when it is eofScanLatestBytes or eofScanAllBytes the stream is split on the TCPEndOfFrame delimiter and one event is raised per logical frame. The Data parameter exposes the decoded bytes as a TMemoryStream positioned at 0; read it immediately because the stream is owned by the client and becomes invalid after the handler returns. By default NotifyEvents is neAsynchronous, so OnBinary is synchronized with the main thread and it is safe to update UI controls from the handler; switch to neNoSync if you need to avoid synchronization and handle thread-safety yourself.
procedure OnBinary(Connection: TsgcWSConnection; const Data: TMemoryStream);
var
oBytes: TBytes;
begin
SetLength(oBytes, Data.Size);
Data.Position := 0;
Data.ReadBuffer(oBytes[0], Data.Size);
// ... process the raw TCP payload
end;