TsgcWebSocketHTTPServer事件 › OnBinary

OnBinary 事件

每次客户端发送二进制消息且服务器收到时触发。

语法

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

默认值

备注

OnBinary 在从 WebSocket 客户端接收到完整的二进制载荷并完成缓冲后触发一次。Data 参数以位置为 0 的 TMemoryStream 形式公开解码后的字节;请在处理程序内部读取它,因为该流由服务器拥有,处理程序返回后即失效。默认情况下 NotifyEvents 为 neAsynchronous,因此 OnBinary 与主线程同步,可安全访问 UI 控件;当吞吐量更重要时,切换到 neNoSync 可在连接线程上分发。如果 Options.FragmentedMessages 为 frgOnlyFragmented,则不会引发此事件,而是使用 OnFragmented。

示例


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;

返回事件