TsgcWebSocketServer_HTTPAPIProperties › HeartBeat

HeartBeat Property

Sends periodic ping frames to keep idle WebSocket connections alive and detect dead peers.

Syntax

property HeartBeat: TsgcWSHeartBeat_Options read GetHeartBeat write SetHeartBeat;

Default Value

Enabled=False

Remarks

When HeartBeat.Enabled is True the server sends a ping to every connected client every Interval seconds. Use Timeout to close peers that do not pong within the given number of seconds (0 disables the check). The OnBeforeHeartBeat event lets you replace the standard ping with a custom message by setting the Handled parameter to True. Heartbeats are especially important on cloud load balancers and NAT devices that silently drop idle TCP connections.

Example


oServer := TsgcWebSocketServer_HTTPAPI.Create(nil);
oServer.HeartBeat.Interval := 30;
oServer.HeartBeat.Timeout := 0;
oServer.HeartBeat.Enabled := true;
oServer.Active := true;

Back to Properties