private void ReceiveCompleted(object sender, SocketAsyncEventArgs e) { if (e.BytesTransferred > 0 && e.SocketError == SocketError.Success) { IRUdpSession session; if (!SessionPool.ActiveList.TryGetValue(e.RemoteEndPoint, out session)) { session = SessionPool.Pop(); session.EndPoint = e.RemoteEndPoint; } session.ReceiveCompleted(sender, e); } this.BeginReceive(e); }
private void ProcessAccept(object sender, SocketAsyncEventArgs e) { try { if (e.SocketError == SocketError.Success) { //从会话连接池获取一个会话对象,避免创建对象和垃圾回收造成的开销 var _channel = _sessionPool.Pop(); //通信开始 _channel.OnAccept(e.AcceptSocket); //将会话保存到在线列表中 _session.Add(_channel); } } catch (Exception excep) { } finally { e.AcceptSocket = null; StartAccept(e); } }