/// <summary> /// Callback for when a connection had disconnected /// </summary> /// <param name="sender">The client object whom is disconnecting</param> private void GpspClient_OnDisconnect(GpspClient client) { // Release this stream's AsyncEventArgs to the object pool base.Release(client.Stream); if (Clients.TryRemove(client.ConnectionID, out client) && !client.Disposed) { client.Dispose(); } }
/// <summary> /// When a new connection is established, we the parent class are responsible /// for handling the processing /// </summary> /// <param name="Stream">A GamespyTcpStream object that wraps the I/O AsyncEventArgs and socket</param> protected override void ProcessAccept(GamespyTcpStream Stream) { // Get our connection id long ConID = Interlocked.Increment(ref ConnectionCounter); GpspClient client; try { // Convert the TcpClient to a MasterClient client = new GpspClient(Stream, ConID); Clients.TryAdd(ConID, client); // Start receiving data Stream.BeginReceive(); } catch { // Remove pending connection Clients.TryRemove(ConID, out client); } }