/// <summary> /// 处理连接请求 /// </summary> private void ProcessConnected(object obj) { SocketAsyncEventArgs e = obj as SocketAsyncEventArgs; UserToken token = (UserToken)e.UserToken; if (e.SocketError == SocketError.Success) { if (_channel != null) { throw new Exception("TcpClient channel is created."); } // 创建频道 _channel = new TcpChannel(); _channel.InitChannel(_syncContext, e.ConnectSocket, _packageCoderType, _packageBodyMaxSize); } else { MotionLog.Error($"Network connecte error : {e.SocketError}"); } // 回调函数 if (token.Callback != null) { token.Callback.Invoke(e.SocketError); } }
/// <summary> /// 处理接收请求 /// </summary> private void ProcessAccept(object obj) { SocketAsyncEventArgs e = obj as SocketAsyncEventArgs; if (e.SocketError == SocketError.Success) { // 创建频道 TcpChannel channel = new TcpChannel(); channel.InitChannel(e.AcceptSocket, _packageCoderType, _packageMaxSize); // 加入到频道列表 lock (_allChannels) { _allChannels.Add(channel); } } else { MotionLog.Log(ELogLevel.Error, $"ProcessAccept error : {e.SocketError}"); } // 投递下一个接收请求 StartAccept(e); }