TsgcSSEClient › Events › OnReconnect

OnReconnect Event

Fires before every reconnection attempt so the delay can be changed or the reconnection cancelled.

Syntax

property OnReconnect: TsgcSSEReconnectEvent;
// TsgcSSEReconnectEvent = procedure(Sender: TObject; aAttempt: Integer;
//   var aDelay: Integer; var aCancel: Boolean) of object

Default Value

—

Remarks

aAttempt is the number of consecutive failed attempts, starting at 1. aDelay is the wait in milliseconds calculated from ReconnectOptions or from the retry: value sent by the server, and can be changed. Set aCancel to True to stop reconnecting, and the client closes. This event always runs on the background thread, whatever the value of NotifyEvents.

Example


procedure TForm1.OnSSEReconnect(Sender: TObject; aAttempt: Integer;
  var aDelay: Integer; var aCancel: Boolean);
begin
  // stop after the fifth failed attempt, otherwise wait at least 2 seconds
  if aAttempt > 5 then
    aCancel := True
  else if aDelay < 2000 then
    aDelay := 2000;
end;

Back to Events