TsgcWebSocketHTTPServerEvents › 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 WebSocket session 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 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. This event is not raised for plain HTTP requests; those end silently once the response has been flushed.

Example


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

Back to Events