private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs) { try { var client = new SocketClient(acceptEventArgs.AcceptSocket); client.Disconnected += OnClientDisconnected; ConnectedClients.Add(client); SocketAcceptd?.Invoke(new SocketAcceptEventArgs { AcceptSocket = acceptEventArgs.AcceptSocket }); } catch (Exception ex) { SimpleLog.Error($"Accept Client Failed, IpEndPoint:{acceptEventArgs.AcceptSocket.RemoteEndPoint}", ex); } StartAccept(acceptEventArgs); //把当前异步事件释放,等待下次连接 }
private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs) { try { var client = new TcpSocketClient(acceptEventArgs.AcceptSocket); client.Disconnected += OnClientDisconnected; ConnectedClients.Add(client); SocketAcceptd?.Invoke(new SocketAcceptEventArgs { AcceptClient = client }); Console.WriteLine($"socket accepted, remote address:{acceptEventArgs.AcceptSocket.RemoteEndPoint}"); } catch (Exception ex) { LastException = ex; } StartAccept(acceptEventArgs); //把当前异步事件释放,等待下次连接 }