TsgcWebSocketServer › Events › OnBeforeHeartBeat
Fires before each HeartBeat ping so the application can implement a custom keep-alive.
public event TsgcWSOnBeforeHeartBeatEventHandler OnBeforeHeartBeat;
// delegate void TsgcWSOnBeforeHeartBeatEventHandler(TObject Sender, TsgcWSConnection Connection, out bool Handled)
—
When HeartBeat is enabled the server sends a standard WebSocket ping to every connected client every HeartBeat.Interval seconds. OnBeforeHeartBeat is raised immediately before that ping is written for each connection so the application can emit its own keep-alive payload on the supplied Connection. Setting Handled to True suppresses the default ping for this cycle; leaving it False (the default) lets the standard ping be sent after the handler returns. Use it to implement protocol-specific heartbeats or to vary the payload per connection.
void OnBeforeHeartBeat(TObject Sender, TsgcWSConnection Connection, out bool Handled)
{
Connection.WriteData("ping");
Handled = true;
}