TsgcWebSocketServer_HTTPAPIEvents › OnDisconnect

OnDisconnect Event

Fires every time a WebSocket connection with a client is dropped.

Syntax

public event TsgcWSDisconnectEventHandler OnDisconnect;
// delegate void TsgcWSDisconnectEventHandler(TsgcWSConnection Connection, int Code)

Default Value

Remarks

OnDisconnect is raised whenever an active client session ends, either because the application called Disconnect or DisconnectAll, the client closed the connection, or the underlying HTTP.SYS request was terminated. The Code parameter carries the WebSocket close code reported by the peer (1000 for a normal closure, 1006 for an abnormal drop...). 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.

Example


void OnDisconnect(TsgcWSConnection Connection, int Code)
{
  Console.WriteLine("Client " + Connection.Guid + " disconnected (code " + Code + ")");
}

Back to Events