TsgcWebSocketServer › Events › OnBinary
Fires every time a client sends a binary message and it is received by the server.
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 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. 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;