TsgcWebSocketClientProperties › WatchDog

WatchDog Property

Automatically reconnects to the server after an unexpected disconnection.

Syntax

property WatchDog: TsgcWSWatchDogClient_Options read FWatchDog write SetWatchDog;

Default Value

Enabled=False, Interval=10, Attempts=0, Backoff=wdbFixed, BackoffMultiplier=2.0, MaxInterval=0, Jitter=0

Remarks

When WatchDog.Enabled is True, the client detects a dropped connection and tries to reconnect every Interval seconds. Attempts controls the maximum number of reconnect attempts; zero means unlimited retries. Use the OnBeforeWatchDog event to customise the reconnection flow, for example to fall back to a secondary server or cancel the retry by setting Handled to True.

The delay between reconnection attempts can grow exponentially instead of staying fixed. Backoff selects the strategy: wdbFixed (default) waits Interval seconds between every attempt, while wdbExponential multiplies the delay by BackoffMultiplier (default 2.0) after each failed attempt, starting from Interval. MaxInterval caps the computed delay in seconds (0 means no cap). Jitter adds a random factor between 0 and 1 to the delay (for example 0.2 varies each delay by up to ±20%), which prevents many clients from reconnecting at exactly the same time after a server restart; setting Jitter greater than zero enables the backoff engine even when Backoff is wdbFixed. The attempt counter resets once a connection is established.

Example


oClient := TsgcWebSocketClient.Create(nil);
oClient.WatchDog.Interval := 10;
oClient.WatchDog.Attempts := 0;
// exponential backoff: 10, 20, 40... up to 300 seconds, with 20% jitter
oClient.WatchDog.Backoff := wdbExponential;
oClient.WatchDog.MaxInterval := 300;
oClient.WatchDog.Jitter := 0.2;
oClient.WatchDog.Enabled := true;
oClient.Active := true;

Back to Properties