예제 #1
0
        public void ProcessReceive(SocketAsyncEventArgs e)
        {
            UserToken token = pool.Pop(); token.conn = sendSocket; token.SendSAEA.RemoteEndPoint = e.RemoteEndPoint;

            //判断网络消息接收是否成功
            if (e.BytesTransferred > 0 && e.SocketError == SocketError.Success)
            {
                byte[] message = new byte[e.BytesTransferred];
                Buffer.BlockCopy(e.Buffer, 0, message, 0, e.BytesTransferred);
                //处理接收到的消息
                token.Receive(message);
                StartReceive();
            }
            else
            {
                if (e.SocketError != SocketError.Success)
                {
                    ClientClose(token, e.SocketError.ToString());
                }
                else
                {
                    //消息长度为0就认为客户端主动断开连接
                    ClientClose(token, "客户端主动断开连接");
                }
            }
        }
예제 #2
0
        public void ProcessAccept(SocketAsyncEventArgs e)
        {
            UserToken token = pool.Pop();

            token.conn = e.AcceptSocket;
            // 通知应用层 有客户端连接

            //开启消息到达监听
            StartReceive(token);
            //释放当前异步对象
            StartAccept(e);
        }
예제 #3
0
        public void ProcessAccept(SocketAsyncEventArgs e)
        {
            //从连接对象池取出连接对象,供新用户使用
            UserToken token = pool.Pop();

            token.conn = e.AcceptSocket;
            //通知应用层有客户端连接
            Center.ClientConnect(token);
            //开启消息到达监听
            StartReceive(token);
            //释放当前异步对象
            StartAccept(e);
        }