コード例 #1
0
        private void ProcessReceive(SocketAsyncEventArgs e)
        {
            logger.Info("ProcessReceive()");


            AsyncUserToken token = e.UserToken as AsyncUserToken;

            //处理接受到的数据前,先清除receivebuf,释放BufferManager
            token.ClearReceiveBuf();
            if (e.SocketError == SocketError.Success)
            {
                logger.Info("received {0} bytes from client {1}", e.BytesTransferred, token.WorkSocket.RemoteEndPoint);

                if (e.BytesTransferred == 0)
                {
                    logger.Info("connection has been disconnceted from client " + token.WorkSocket.RemoteEndPoint);
                    CloseAndRelease(e);
                    return;
                }

                if (!HandlePacket(e)) //处理数据失败
                {
                    logger.Error("handle failed.");
                    CloseAndRelease(e);
                }
                else
                {
                }
            }
            else
            {
                logger.Error("receive failed " + e.SocketError.ToString());
                CloseAndRelease(e);
            }
        }