TsgcHTTP2Client | Client Keep Connection Active

Once your client has connected to server, sometimes connection can be closed due to poor signal, connection errors... there are 2 properties which helps to keep connection active.

 

HeartBeat

HeartBeat property allows to send a Ping every X seconds to maintain connection alive. Some servers, close TCP connections if there is no data exchanged between peers. HeartBeat solves this problem, sending a ping every a specific interval. Usually this is enough to maintain a connection active.

 

The property HeartBeatType allows to customize how the HeartBeat works:

 

1. hbtAlways: sends a ping every x seconds defined in the Interval.

2. hbtOnlyIfNoMsgRcvInterval: sends a ping every x seconds only if no messages has been received during the latest x seconds defined in the Interval property.

 

Example: send a ping every 30 seconds


oClient := TsgcHTTP2Client.Create(nil);
oClient.HeartBeat.Interval := 30;
oClient.HeartBeat.Enabled := true;
oClient.Active := true;

WatchDog

If WatchDog is enabled, when client detects a disconnection, WatchDog try to reconnect again every X seconds until connection is active again.

 

Example: reconnect every 10 seconds after a disconnection with unlimited attempts.

 


oClient := TsgcHTTP2Client.Create(nil);
oClient.WatchDog.Interval := 10;
oClient.WatchDog.Attempts := 0;
oClient.WatchDog.Enabled := true;
oClient.Active := true;