TsgcWebSocketServer_HTTPAPIEvents › OnBinary

OnBinary Event

Fires every time a client sends a binary message and it is received by the server.

Syntax

property OnBinary: TsgcWSBinaryEvent;
// TsgcWSBinaryEvent = procedure(Connection: TsgcWSConnection; const Data: TMemoryStream) of object

Default Value

Remarks

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. The event runs on the IOCP worker thread that handled the incoming HTTP.SYS WebSocket frame, so marshal to the main thread before touching UI controls. If Options.FragmentedMessages is frgOnlyFragmented the event is not raised and OnFragmented is used instead.

Example


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;

Back to Events