TsgcWebSocketServer_HTTPAPIZdarzenia › OnFragmented

OnFragmented Zdarzenie

Wywoływane po odebraniu fragmentu wiadomości (tylko gdy Options.FragmentedMessages ma wartość frgAll lub frgOnlyFragmented).

Składnia

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

Wartość domyślna

Uwagi

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ń.

Przykład


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

Powrót do Zdarzeń