TsgcWSAPIServer_MCP › Methods › KeepAlive
Sends a keep-alive frame on the supplied connection to prevent idle disconnection.
procedure KeepAlive(const aConnection: TsgcWSConnection; const aMessage: string);
| Name | Type | Description |
|---|---|---|
aConnection | const TsgcWSConnection | Target streaming connection (typically the one stored on TsgcAI_MCP_Session.Connection). |
aMessage | const string | Optional payload to write alongside the keep-alive probe; pass an empty string to send a minimal frame. |
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.
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;