TsgcWebSocketClient › Events › OnBeforeWatchDog
Fires before each WatchDog reconnection attempt so the application can adjust the target server or suppress the retry.
public event TsgcWSOnBeforeWatchDogEventHandler OnBeforeWatchDog;
// delegate void TsgcWSOnBeforeWatchDogEventHandler(TObject Sender, out bool Handled)
—
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.
void OnBeforeWatchDog(TObject Sender, out bool Handled)
{
TsgcWebSocketClient oClient = (TsgcWebSocketClient)Sender;
if (oClient.WatchDog.AttemptsCount > 3)
oClient.Host = "fallback.example.com";
Handled = false;
}