TsgcWebSocketServer_HTTPAPIProperties › HeartBeat

HeartBeat Property

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

Syntax

public TsgcWSHeartBeat_Options HeartBeat { get; set; }

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 = new TsgcWebSocketServer_HTTPAPI();
oServer.HeartBeat.Interval = 30;
oServer.HeartBeat.Timeout = 0;
oServer.HeartBeat.Enabled = true;
oServer.Active = true;

Back to Properties