TsgcWebSocketProxyServer › Events › OnBinary
Fires every time a downstream WebSocket client sends a binary message, before the proxy forwards it upstream.
property OnBinary: TsgcWSBinaryEvent;
// TsgcWSBinaryEvent = procedure(Connection: TsgcWSConnection; const Data: TMemoryStream) of object
—
OnBinary is raised once a full binary payload has been received and buffered from a downstream WebSocket client. The Data parameter exposes the decoded bytes as a TMemoryStream positioned at 0; read it inside the handler because the stream is owned by the server and becomes invalid after the handler returns. The proxy relays this payload to the upstream TCP server (Proxy.Host, Proxy.Port) right after the handler returns, so it is a convenient place to inspect or log the frame before it is forwarded. By default NotifyEvents is neAsynchronous, so OnBinary is synchronized with the main thread and it is safe to touch UI controls; switch to neNoSync to dispatch on the connection thread when throughput matters. If Options.FragmentedMessages is frgOnlyFragmented the event is not raised and OnFragmented is used instead.
procedure OnBinary(Connection: TsgcWSConnection; const Data: TMemoryStream);
var
oBitmap: TBitmap;
begin
oBitmap := TBitmap.Create;
try
oBitmap.LoadFromStream(Data);
Image1.Picture.Assign(oBitmap);
finally
FreeAndNil(oBitmap);
end;
end;