TsgcHTTPServer › Events › OnDisconnect
Fires every time a client connection is dropped.
property OnDisconnect: TsgcWSDisconnectEvent;
// TsgcWSDisconnectEvent = procedure(Connection: TsgcWSConnection; Code: Integer) of object
—
OnDisconnect is raised whenever an active client connection ends, either because the application called Disconnect or DisconnectAll, the client closed the connection, or the TCP socket was dropped unexpectedly. The Code parameter carries the numeric close code used across the shared sgc server engine (1000 for a normal closure, 1006 for an abnormal drop); TsgcHTTPServer never performs a WebSocket close handshake, so the code reflects how the connection ended rather than a value negotiated with the client. After this event returns the Connection object is no longer valid for sending data, so release any per-session resources you had associated with its Guid.
procedure OnDisconnect(Connection: TsgcWSConnection; Code: Integer);
begin
Log(Format('Client %s disconnected (code %d)', [Connection.Guid, Code]));
end;