TsgcWebSocketClient › Zdarzenia › OnFragmented
Wywoływane dla każdego odebranego fragmentu, gdy właściwość Options.FragmentedMessages ma wartość frgAll lub frgOnlyFragmented.
property OnFragmented: TsgcWSFragmentedEvent;
// TsgcWSFragmentedEvent = procedure(Connection: TsgcWSConnection; const Data: TMemoryStream; const OpCode: TOpCode; const Continuation: Boolean) of object
—
Domyślnie (Options.FragmentedMessages = frgOnlyBuffer) klient buforuje fragmenty wiadomości i wywołuje OnMessage lub OnBinary po odebraniu pełnego ładunku. Ustaw właściwość na frgOnlyFragmented, aby odbierać tylko OnFragmented na każdy fragment, lub na frgAll, aby odbierać OnFragmented dla każdego fragmentu, a następnie OnMessage/OnBinary po zakończeniu wiadomości. Parametr Data to TMemoryStream z bajtami bieżącego fragmentu, OpCode wskazuje oryginalny typ ramki (tekst, binarne, kontynuacja...), a Continuation wynosi True, gdy oczekiwane są kolejne fragmenty, i False na ostatnim fragmencie. To zdarzenie jest przydatne do raportowania postępu dużych strumieni.
procedure OnFragmented(Connection: TsgcWSConnection; const Data: TMemoryStream;
const OpCode: TOpCode; const Continuation: Boolean);
begin
ShowProgress(Data.Size);
if not Continuation then
SaveStream(Data);
end;