TsgcWebSocketClientEvents › OnDisconnect

OnDisconnect Event

Fires when the WebSocket connection has been dropped or closed.

Syntax

property OnDisconnect: TsgcWSDisconnectEvent;
// TsgcWSDisconnectEvent = procedure(Connection: TsgcWSConnection; Code: Integer) of object

Default Value

Remarks

OnDisconnect is raised whenever the WebSocket session ends, either because the application set Active to False, the server sent a close frame, or the TCP connection was dropped unexpectedly. The Code parameter carries the WebSocket close code reported by the peer (1000 for a normal closure, 1006 for an abnormal drop, etc.). After this event fires the Connection object is no longer valid for sending data; if WatchDog is enabled the client will schedule a reconnection attempt and raise OnBeforeWatchDog before retrying.

Example


procedure OnDisconnect(Connection: TsgcWSConnection; Code: Integer);
begin
  Log(Format('Disconnected (code %d)', [Code]));
end;

Back to Events