Пример #1
0
 /// <summary>
 /// 移除指定客户端
 /// </summary>
 /// <param name="client">指定客户端对象</param>
 internal void RemoveExistClient(RemoteConnection client)
 {
     if (serverSocket.SocketType != SocketType.Stream)
     {
         return;
     }
     lock (remoteTCPClients)
     {
         if (remoteTCPClients.Contains(client))
         {
             remoteTCPClients.Remove(client);
             // close the socket associated with the client
             try
             {
                 client.Socket.Close();
             }
             // throws if client process has already closed
             catch (Exception ex)
             {
                 // Log.Exception(ex, "ServerConnection", "CloseClientSocket", "Socket");
                 socketInvoke.SocketException(ex);
             }
             // 断开连接回调
             if (socketStatusListener != null)
             {
                 socketStatusListener.OnClose(client);
             }
             // decrement the counter keeping track of the total number of clients connected to the server
             Interlocked.Decrement(ref numConnectedSockets);
             // Free the SocketAsyncEventArg so they can be reused by another client
             readWritePool.Enqueue(client.readWriteEventArg);
             maxNumberAcceptedClients.Release();
             // Log.Info("CloseClientSocket A client has been disconnected from the server. There are " + numConnectedSockets + " clients connected to the server" );
         }
     }
 }