Пример #1
0
        private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
        {
            ITcpSession session = sessionPool.Pop();

            if (session != null)
            {
                session.ConnectSocket = acceptEventArgs.AcceptSocket;
                OnConnected(session);        //启动连接请求通过事件
                session.StartReceiveAsync(); //开始接收数据
            }
            else
            {
                Loger.Warning("TcpServer:session is null");
                acceptEventArgs.AcceptSocket.Dispose();
            }
            StartAccept(acceptEventArgs); //把当前异步事件释放,等待下次连接
        }
Пример #2
0
        private void ProcessAccept(SocketAsyncEventArgs acceptEventArgs)
        {
            ITcpSession session = sessionPool.Pop();

            if (session != null)
            {
                session.Server = this;
                OnlineList.TryAdd(session.SessionId, session);
                session.ConnectSocket   = acceptEventArgs.AcceptSocket;
                session.ConnectDateTime = DateTime.Now;
                session.ActiveDateTime  = session.ConnectDateTime;
                if (OnConnected != null)
                {
                    OnConnected(this, session); //启动连接请求通过事件
                }
                session.StartReceiveAsync();    //开始接收数据
            }
            StartAccept(acceptEventArgs);       //把当前异步事件释放,等待下次连接
        }