Ejemplo n.º 1
0
        private void Newclient(Socket clientSocket, object token)
        {
            while (_communicatorPool.StackSize() == 0)
            {
                Thread.Sleep(100);//wait until Resource is ready
            }
            if (_communicatorPool.StackSize() > 0)
            {
                Communicator communicator = _communicatorPool.Pop();
                User         user         = _userPool.Pop();

                user.SetUserSocket(null); //initialize members before using
                communicator.SetUser(null);
                communicator.OperationState = true;
                communicator.ReceivedBytesTransferredCount = 0;
                communicator.SentBytesTransferredCount     = 0;
                user.UserId = 0;

                ServerProcessManager manager = new ServerProcessManager(user, communicator);
                manager.Start(clientSocket);
                ResetAssets(communicator, user);
                _userPool.Push(user);
                _communicatorPool.Push(communicator);//push it back after operation
            }
        }
Ejemplo n.º 2
0
        public void InitializePool(int maximumClients)//This method should be called before
        {
            // _userPool=new UserPool(maximumClients);
            _communicatorPool = new CommunicatorPool(maximumClients);
            _userPool         = new UserPool(maximumClients);
            BufferManager sendBuffer    = new BufferManager(maximumClients, BufferSize);
            BufferManager receiveBuffer = new BufferManager(maximumClients, BufferSize);

            for (int i = 0; i < maximumClients; i++)                          // Fill out the stack pool Initially
            {
                SocketAsyncEventArgs sendArg    = new SocketAsyncEventArgs(); // Create new Socket Pool for sending and receiving
                SocketAsyncEventArgs receiveArg = new SocketAsyncEventArgs();

                sendBuffer.SetBuffer(sendArg); // Set buffer for sendArg and receiveArg objects
                receiveBuffer.SetBuffer(receiveArg);

                _communicatorPool.Push(new Communicator(sendArg, receiveArg));
                _userPool.Push(new User(0));

                //_userPool.Push(new User(i));// put UserToken and UserID for the user initially
            }
        }