/// <summary> /// 客户端断开连接 /// </summary> /// <param name="client"></param> /// <param name="reason"></param> private void Disconnect(ClientPeer client, string reason) { try { if (client == null) { throw new Exception("客户端为空,无法断开连接"); } Console.WriteLine(client.ClientSocket.RemoteEndPoint + "客户端断开连接,原因" + reason); application.Disconnect(client); // 应用层断开连接 client.Disconnect(); // 让客户端处理断开连接 clientPeerPool.Enqueue(client); // 回收 semaphore.Release(); // 退出信号量并返回前一个计数 } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// 客户端断开连接 /// </summary> /// <param name="client"></param> /// <param name="reason"></param> private void Disconnect(ClientPeer client, string reason) { try { if (client == null) { throw new Exception("客服端为空,无法连接"); } application.Disconnect(client); Console.WriteLine(client.clientSockert.RemoteEndPoint + "断开连接原因:" + reason); client.Disconnect(); clientPeerPool.Enqueue(client); semaphore.Release(); } catch (Exception e) { Console.WriteLine(e.Message); } }