TsgcWSAPIServer_MCPMethods › KeepAlive

KeepAlive Method

Sends a keep-alive frame on the supplied connection to prevent idle disconnection.

Syntax

procedure KeepAlive(const aConnection: TsgcWSConnection; const aMessage: string);

Parameters

NameTypeDescription
aConnectionconst TsgcWSConnectionTarget streaming connection (typically the one stored on TsgcAI_MCP_Session.Connection).
aMessageconst stringOptional payload to write alongside the keep-alive probe; pass an empty string to send a minimal frame.

Remarks

Inherited helper from the API base class that writes a keep-alive probe on a long-lived transport so proxies and firewalls do not close the connection during idle periods. It is mainly relevant when TransportOptions.HttpStreamable.Enabled is True and the session maintains an open streaming channel (HTTP chunked transfer or Server-Sent Events). Call it periodically from a timer or after long server-side operations.

Example

procedure TMainForm.TimerKeepAliveTimer(Sender: TObject);
var
  i: Integer;
  oSession: TsgcAI_MCP_Session;
begin
  for i := 0 to MCPServer.MCPOptions.SessionTimeout - 1 do ; // pseudocode
  oSession := MCPServer.MCPServer.Sessions.Items[0];
  if Assigned(oSession) and Assigned(oSession.Connection) then
    MCPServer.KeepAlive(oSession.Connection, '');
end;

Back to Methods