TsgcWebSocketClient › Events › OnBeforeWatchDog
Fires before each WatchDog reconnection attempt so the application can adjust the target server or suppress the retry.
property OnBeforeWatchDog: TsgcWSOnBeforeWatchDogEvent;
// TsgcWSOnBeforeWatchDogEvent = procedure(Sender: TObject; var Handled: Boolean) of object
—
When WatchDog is enabled and an unexpected disconnection is detected, the client waits WatchDog.Interval seconds and then tries to reconnect. OnBeforeWatchDog is raised just before each attempt, which allows the application to change the server connection properties (Host, Port, URL, TLS...) to implement fallback logic such as switching to a secondary server after several failed attempts. Setting Handled to True cancels the reconnection attempt for this cycle; leaving it False (the default) lets the WatchDog proceed with the reconnect.
procedure OnBeforeWatchDog(Sender: TObject; var Handled: Boolean);
var
oClient: TsgcWebSocketClient;
begin
oClient := TsgcWebSocketClient(Sender);
if oClient.WatchDog.AttemptsCount > 3 then
oClient.Host := 'fallback.example.com';
Handled := False;
end;