TsgcWebSocketClientEvents › OnBeforeHeartBeat

OnBeforeHeartBeat Event

Fires before each HeartBeat ping so the application can send a custom keep-alive message.

Syntax

public event TsgcWSOnBeforeHeartBeatEventHandler OnBeforeHeartBeat;
// delegate void TsgcWSOnBeforeHeartBeatEventHandler(TObject Sender, TsgcWSConnection Connection, out bool Handled)

Default Value

Remarks

When HeartBeat is enabled the client sends a standard WebSocket ping every HeartBeat.Interval seconds. OnBeforeHeartBeat is raised immediately before that ping is written so the application can emit its own keep-alive payload using the supplied Connection. Setting Handled to True suppresses the default ping; leaving it False (the default) lets the standard ping be sent after the handler returns.

Example


void OnBeforeHeartBeat(TObject Sender, TsgcWSConnection Connection, out bool Handled)
{
  Connection.WriteData("ping");
  Handled = true;
}

Back to Events