/// <summary> /// 关闭 /// </summary> public override void Close() { Console.WriteLine("{0} 连接断开", _Socket.RemoteEndPoint); AsyncClientPool.RemoveClient(this); Facade.RemoveCore(_Socket.RemoteEndPoint.ToString()); _Socket.Close(); if (_commandHandler != null) { _commandHandler.Close(); } }
/// <summary> /// 异步建立客户端连接回调 /// </summary> private void AcceptCallBack(IAsyncResult ar) { try { Socket _socket = listen.EndAccept(ar); AsyncClientPool.AddClient(new AsyncTcpClient(_socket)); Console.WriteLine("客户端连接 [{0}]", _socket.RemoteEndPoint.ToString()); listen.BeginAccept(AcceptCallBack, null); } catch (Exception e) { Console.WriteLine("异步建立客户端连接失败:" + e.Message); } }