TsgcWebSocketProxyServerEvents › OnBeforeHeartBeat

OnBeforeHeartBeat Event

Fires before each HeartBeat ping so the application can implement a custom keep-alive for a downstream WebSocket client.

Syntax

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

Default Value

Remarks

When HeartBeat is enabled the proxy server sends a standard WebSocket ping to every connected downstream 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; only the WebSocket leg is pinged here, the upstream TCP link is not touched by this event.

Example


procedure OnBeforeHeartBeat(Sender: TObject; const Connection: TsgcWSConnection;
  var Handled: Boolean);
begin
  Connection.WriteData('ping');
  Handled := True;
end;

Back to Events