/// <summary>
        /// 异步Socket TCP服务器
        /// </summary>
        /// <param name="localIPAddress">监听的IP地址</param>
        /// <param name="listenPort">监听的端口</param>
        /// <param name="maxClient">最大客户端数量</param>
        public IOCPServer(IPAddress localIPAddress, int listenPort, int maxClient)
        {
            this.Address  = localIPAddress;
            this.Port     = listenPort;
            this.Encoding = Encoding.Default;

            _maxClient = maxClient;

            _serverSock = new Socket(localIPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            _bufferManager = new BufferManager(_bufferSize * _maxClient * opsToPreAlloc, _bufferSize);

            _objectPool = new SocketAsyncEventArgsPool(_maxClient);

            _maxAcceptedClients = new Semaphore(_maxClient, _maxClient);

            _oderAnalyze = new ProtocolAnalyze();
        }
Beispiel #2
0
        //接收消息客户端是否合法
        private bool isLegal(EndPoint remote)
        {
            bool judge = false;
            List <AsyncUserToken> connMsg = ProtocolAnalyze.GetClientMeg();//查看登录列表,检查客户端是否合法

            if (connMsg == null)
            {
                return(judge);
            }
            foreach (var client in connMsg)
            {
                if (client.IPAddress.ToString() == ((IPEndPoint)remote).Address.ToString())
                {
                    judge = true;
                    break;
                }
            }
            return(judge);
        }