TsgcWebSocketClientEvents › OnFragmented

OnFragmented 事件

当 Options.FragmentedMessages 为 frgAll 或 frgOnlyFragmented 时,每接收到一个分片就触发一次。

语法

property OnFragmented: TsgcWSFragmentedEvent;
// TsgcWSFragmentedEvent = procedure(Connection: TsgcWSConnection; const Data: TMemoryStream; const OpCode: TOpCode; const Continuation: Boolean) of object

默认值

备注

默认情况下(Options.FragmentedMessages = frgOnlyBuffer),客户端缓冲消息的分片,并在收到完整负载后触发 OnMessage 或 OnBinary。将该属性设置为 frgOnlyFragmented 可对每个分片仅接收 OnFragmented 事件,或设置为 frgAll 可同时接收每个分片的 OnFragmented 事件和消息完成时的 OnMessage/OnBinary 事件。Data 参数是包含当前分片字节的 TMemoryStream,OpCode 指示原始帧类型(文本、二进制、续传帧等),当还有更多分片时 Continuation 为 True,在最后一个分片时为 False。此事件可用于报告大型流的传输进度。

示例


procedure OnFragmented(Connection: TsgcWSConnection; const Data: TMemoryStream;
  const OpCode: TOpCode; const Continuation: Boolean);
begin
  ShowProgress(Data.Size);
  if not Continuation then
    SaveStream(Data);
end;

返回事件