TsgcWebSocketServer_HTTPAPI › 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 i wywołuje OnMessage lub OnBinary po odebraniu pełnego ładunku. Ustawienie FragmentedMessages na frgOnlyFragmented powoduje odbieranie wyłącznie OnFragmented na każdy fragment, a ustawienie frgAll powoduje odbieranie OnFragmented na każdy fragment, 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 przyjmuje wartość True, gdy oczekiwane są kolejne fragmenty, i False dla ostatniego fragmentu. Zdarzenie to jest przydatne do raportowania postępu dużych przesyłań.
procedure OnFragmented(Connection: TsgcWSConnection; const Data: TMemoryStream;
const OpCode: TOpCode; const Continuation: Boolean);
begin
ShowProgress(Data.Size);
if not Continuation then
SaveStream(Data);
end;