Пример #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
            }
        }
 private void SetSocket(Socket socket)
 {
     _user.SetUserSocket(socket);
     _serverCommunicator.SetUser(_user);
 } //Sets socket for the communicator