Example #1
0
        /// <summary>
        /// 初始化发送对象池
        /// </summary>
        /// <param name="maxNumber"></param>
        private void InitializePool(int maxNumberOfConnections)
        {
            if (sendTokenManager != null)
            {
                sendTokenManager.Clear();
            }
            if (sBufferManager != null)
            {
                sBufferManager.Clear();
            }

            sendTokenManager = new SocketTokenManager <SocketAsyncEventArgs>(maxNumberOfConnections);
            sBufferManager   = new SocketBufferManager(maxNumberOfConnections, cliRecBufferSize);

            for (int i = 0; i < maxNumberOfConnections; ++i)
            {
                SocketAsyncEventArgs tArgs = new SocketAsyncEventArgs()
                {
                    DisconnectReuseSocket = true
                };
                tArgs.Completed += IO_Completed;
                tArgs.UserToken  = new SocketToken(i)
                {
                    TokenSocket = cliSocket,
                    TokenId     = i
                };
                sBufferManager.SetBuffer(tArgs);
                sendTokenManager.Set(tArgs);
            }
        }
        private void InitializePool(int maxNumberOfConnections)
        {
            if (sendTokenManager != null)
            {
                sendTokenManager.Clear();
            }
            if (sBufferManager != null)
            {
                sBufferManager.Clear();
            }
            int cnt = maxNumberOfConnections + offsetNumber;

            sendTokenManager = new SocketTokenManager <SocketAsyncEventArgs>(cnt);
            sBufferManager   = new SocketBufferManager(cnt, receiveChunkSize);

            for (int i = 1; i <= cnt; ++i)
            {
                SocketAsyncEventArgs tArgs = new SocketAsyncEventArgs()
                {
                    DisconnectReuseSocket = true
                };
                tArgs.Completed += IO_Completed;
                tArgs.UserToken  = new SocketToken(i)
                {
                    TokenSocket = socket,
                    TokenId     = i
                };
                sBufferManager.SetBuffer(tArgs);
                sendTokenManager.Set(tArgs);
            }
        }
Example #3
0
 /// <summary>
 /// 初始化接收对象池
 /// </summary>
 private void InitializeAcceptPool()
 {
     acceptPool.Clear();
     for (int i = 0; i < maxNumber; ++i)
     {
         SocketAsyncEventArgs args = new SocketAsyncEventArgs();
         args.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed);
         args.UserToken  = new SocketToken(i);
         recvBuffer.SetBuffer(args);
         acceptPool.Push(args);
     }
 }
Example #4
0
        public void Initialize(int maxNumberOfConnections, int bufferSize = 2048)
        {
            receiveBufferPool = new SocketBufferManager(maxNumberOfConnections, bufferSize);
            receivePool       = new SocketTokenManager <SocketAsyncEventArgs>(maxNumberOfConnections);

            for (int i = 0; i < maxNumberOfConnections; ++i)
            {
                SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs();
                socketArgs.Completed += SocketArgs_Completed;
                receiveBufferPool.SetBuffer(socketArgs);
                receivePool.Push(socketArgs);
            }
        }
        /// <summary>
        /// 初始化发送对象池
        /// </summary>
        /// <param name="maxNumber"></param>
        private void InitializePool(int maxNumber)
        {
            tokenPool.Clear();

            for (int i = 0; i < maxNumber; ++i)
            {
                SocketAsyncEventArgs tArgs = new SocketAsyncEventArgs();
                tArgs.Completed += new EventHandler <SocketAsyncEventArgs>(IO_Completed);
                tArgs.UserToken  = new SocketToken(i);
                sendBufferPool.SetBuffer(tArgs);
                tokenPool.Push(tArgs);
            }
        }
        /// <summary>
        /// 初始化客户端发送对象池
        /// </summary>
        public void Initialize(int maxCountClient, int blockSize = 4096)
        {
            this.maxCount  = maxCountClient;
            this.blocksize = blockSize;
            tokenPool      = new SocketTokenManager <SocketAsyncEventArgs>(maxCountClient);
            sentBufferPool = new SocketBufferManager(maxCountClient, blockSize);

            for (int i = 0; i < maxCount; ++i)
            {
                SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs();
                socketArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ClientSocket_Completed);
                sentBufferPool.SetBuffer(socketArgs);
                tokenPool.Push(socketArgs);
            }
        }
        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="recBufferSize"></param>
        /// <param name="port"></param>
        private void Initialize()
        {
            sendTokenManager  = new SocketTokenManager <SocketAsyncEventArgs>(maxNumberOfConnections);
            sendBufferManager = new SocketBufferManager(maxNumberOfConnections, bufferSizeByConnection);

            //初始化发送接收对象池
            for (int i = 0; i < maxNumberOfConnections; ++i)
            {
                SocketAsyncEventArgs sendArgs = new SocketAsyncEventArgs();
                sendArgs.Completed += IO_Completed;
                sendArgs.UserToken  = cliSocket;
                sendBufferManager.SetBuffer(sendArgs);
                sendTokenManager.Set(sendArgs);
            }
        }
Example #8
0
        /// <summary>
        /// 初始化对象
        /// </summary>
        private void Initialize()
        {
            _sendTokenManager  = new SocketTokenManager <SocketAsyncEventArgs>(_maxNumberOfConnections);
            _sendBufferManager = new SocketBufferManager(_maxNumberOfConnections, _bufferSizeByConnection);

            //初始化发送接收对象池
            for (var i = 0; i < _maxNumberOfConnections; ++i)
            {
                var sendArgs = new SocketAsyncEventArgs();
                sendArgs.Completed += IO_Completed;
                sendArgs.UserToken  = Socket;
                _sendBufferManager.SetBuffer(sendArgs);
                _sendTokenManager.Set(sendArgs);
            }
        }
Example #9
0
        protected bool TCPServerStartFlag = false;   /* 冗余判断服务器是否启动 */
        #endregion

        /// <summary>
        /// 初始化服务器
        /// </summary>
        public void TCPServerInit()
        {
            _TCPServerSocketBufferManager.InitBuffer();

            SocketAsyncEventArgs _SocketAsyncEventArgs;

            /* 预分配SocketAsyncEventArgs对象池 */
            for (int count = 0; count < _TCPServerSocketSetting.DefaultMaxConnctions; count++)
            {
                _SocketAsyncEventArgs            = new SocketAsyncEventArgs();
                _SocketAsyncEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(TCPServerOnIOCompleted);
                _TCPServerSocketBufferManager.SetBuffer(_SocketAsyncEventArgs);

                _TCPServerSocketAsyncEventArgsPool.Push(_SocketAsyncEventArgs);
            }
        }
 /// <summary>
 /// 初始化发送对象池
 /// </summary>
 private void InitializeSendPool()
 {
     sendTokenManager.Clear();
     for (int i = 0; i < maxNumberOfConnections; ++i)
     {
         SocketAsyncEventArgs args = new SocketAsyncEventArgs()
         {
             DisconnectReuseSocket = true,
             SocketError           = SocketError.SocketError
         };
         args.Completed += IO_Completed;
         args.UserToken  = new SocketToken(i);
         sendBufferManager.SetBuffer(args);
         sendTokenManager.Set(args);
     }
 }
        /// <summary>
        /// 初始化客户端发送对象池
        /// </summary>
        /// <param name="maxCountClient"></param>
        /// <param name="blockSize"></param>
        public void Initialize(int maxCountClient, int blockSize = 4096)
        {
            this.maxCount     = maxCountClient;
            this.blockSize    = blockSize;
            sendTokenManager  = new SocketTokenManager <SocketAsyncEventArgs>(maxCountClient);
            sendBufferManager = new SocketBufferManager(maxCountClient, blockSize);

            for (int i = 0; i < maxCount; ++i)
            {
                SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs
                {
                    UserToken = sendSocket
                };
                socketArgs.Completed += ClientSocket_Completed;
                sendBufferManager.SetBuffer(socketArgs);
                sendTokenManager.Set(socketArgs);
            }
        }
 /// <summary>
 /// 初始化接收对象池
 /// </summary>
 private void InitializeAcceptPool()
 {
     acceptTokenManager.Clear();
     for (int i = 0; i < maxNumberOfConnections; ++i)
     {
         SocketAsyncEventArgs args = new SocketAsyncEventArgs()
         {
             DisconnectReuseSocket = true,
             SocketError           = SocketError.SocketError
         };
         args.Completed += Accept_Completed;
         args.UserToken  = new SocketToken(i)
         {
             TokenAgrs = args,
         };
         recvBufferManager.SetBuffer(args);
         acceptTokenManager.Set(args);
     }
 }
Example #13
0
        public SocketSend(Socket socket, int maxCountClient, int blockSize = 4096)
            : base(blockSize)
        {
            this.maxCount = maxCountClient;
            base.socket   = socket;

            sendTokenManager  = new SocketTokenManager <SocketAsyncEventArgs>(maxCountClient);
            sendBufferManager = new SocketBufferManager(maxCountClient, blockSize);

            for (int i = 0; i < maxCount; ++i)
            {
                SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs
                {
                    UserToken = base.socket
                };
                socketArgs.Completed += ClientSocket_Completed;
                sendBufferManager.SetBuffer(socketArgs);
                sendTokenManager.Set(socketArgs);
            }
        }
Example #14
0
        /// <summary>
        /// 初始化发送对象
        /// </summary>
        /// <param name="maxCountClient">客户端最大数</param>
        public SocketSend(int maxCountClient, int blockSize = 4096)
            : base(blockSize)
        {
            this.maxCount         = maxCountClient;
            socket                = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            socket.ReceiveTimeout = receiveTimeout;
            socket.SendTimeout    = sendTimeout;

            sendTokenManager  = new SocketTokenManager <SocketAsyncEventArgs>(maxCountClient);
            sendBufferManager = new SocketBufferManager(maxCountClient, blockSize);

            for (int i = 0; i < maxCount; ++i)
            {
                SocketAsyncEventArgs socketArgs = new SocketAsyncEventArgs
                {
                    UserToken = socket
                };
                socketArgs.Completed += ClientSocket_Completed;
                sendBufferManager.SetBuffer(socketArgs);
                sendTokenManager.Set(socketArgs);
            }
        }
Example #15
0
        private void InitializePool(int maxNumberOfConnections)
        {
            _sendTokenManager?.Clear();
            _sBufferManager?.Clear();

            _sendTokenManager = new SocketTokenManager <SocketAsyncEventArgs>(maxNumberOfConnections);
            _sBufferManager   = new SocketBufferManager(maxNumberOfConnections, receiveChunkSize);

            for (var i = 0; i < maxNumberOfConnections; ++i)
            {
                var tArgs = new SocketAsyncEventArgs()
                {
                    DisconnectReuseSocket = true
                };
                tArgs.Completed += IO_Completed;
                tArgs.UserToken  = new SocketToken(i)
                {
                    TokenSocket = socket,
                    TokenId     = i
                };
                _sBufferManager.SetBuffer(tArgs);
                _sendTokenManager.Set(tArgs);
            }
        }
Example #16
0
        /// <summary>
        /// 初始化发送对象
        /// </summary>
        /// <param name="maxCountClient">客户端最大数</param>
        /// <param name="blockSize"></param>
        public SocketSend(int maxCountClient, int blockSize = 4096)
            : base(blockSize)
        {
            _maxCount = maxCountClient;
            Socket    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
            {
                ReceiveTimeout = ReceiveTimeout,
                SendTimeout    = SendTimeout
            };

            _sendTokenManager  = new SocketTokenManager <SocketAsyncEventArgs>(maxCountClient);
            _sendBufferManager = new SocketBufferManager(maxCountClient, blockSize);

            for (var i = 0; i < _maxCount; ++i)
            {
                var socketArgs = new SocketAsyncEventArgs
                {
                    UserToken = Socket
                };
                socketArgs.Completed += ClientSocket_Completed;
                _sendBufferManager.SetBuffer(socketArgs);
                _sendTokenManager.Set(socketArgs);
            }
        }