TsgcTCPClient › Events › OnBeforeHeartBeat

OnBeforeHeartBeat Event

Fires before each HeartBeat tick so the application can send a custom keep-alive payload.

Syntax

property OnBeforeHeartBeat: TsgcWSOnBeforeHeartBeatEvent;
// TsgcWSOnBeforeHeartBeatEvent = procedure(Sender: TObject; const Connection: TsgcWSConnection; var Handled: Boolean) of object

Default Value

—

Remarks

When HeartBeat is enabled the client wakes up every HeartBeat.Interval seconds to keep the TCP connection alive. Because the plain TCP transport has no built-in ping frame, the default heartbeat is a no-op and the application is expected to emit whatever payload the peer expects (for example a protocol-specific keep-alive packet). OnBeforeHeartBeat is raised on each tick so the application can write that payload through the supplied Connection; setting Handled to True simply documents that the application took care of the heartbeat and leaving it False is equivalent because there is no default packet to send.

Example


procedure OnBeforeHeartBeat(Sender: TObject; const Connection: TsgcWSConnection;
  var Handled: Boolean);
begin
  Connection.WriteData('PING' + #13#10);
  Handled := True;
end;

Back to Events