TsgcWebSocketHTTPServer › Zdarzenia › OnFragmented
Wywoływane po odebraniu fragmentu wiadomości (tylko gdy 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) serwer buforuje fragmenty wiadomości WebSocket i wywołuje OnMessage lub OnBinary po odebraniu pełnego ładunku. Ustawić FragmentedMessages na frgOnlyFragmented, aby odbierać tylko OnFragmented dla każdego fragmentu, 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, binarny, kontynuacja...), a Continuation ma wartość True, gdy oczekiwanych jest więcej fragmentów, i False przy ostatnim fragmencie. To zdarzenie jest przydatne do raportowania postępu dużych przesyłanych plików.
procedure OnFragmented(Connection: TsgcWSConnection; const Data: TMemoryStream;
const OpCode: TOpCode; const Continuation: Boolean);
begin
ShowProgress(Data.Size);
if not Continuation then
SaveStream(Data);
end;