Пример #1
0
        public void HandleRequest()
        {
            try
            {
                StreamReader streamReader = new StreamReader(_context.GetStream());

                _path = streamReader.ReadLine();
                if (String.IsNullOrEmpty(_path))
                {
                    throw new Exception("Invalid request path");
                }
                Console.WriteLine("Request path is {0}", _path);
                string username = streamReader.ReadLine();
                if (String.IsNullOrEmpty(username))
                {
                    Console.WriteLine("No username");
                    throw new Exception("Authentication failed");
                }
                string password = streamReader.ReadLine();
                if (String.IsNullOrEmpty(password))
                {
                    Console.WriteLine("No password");
                    throw new Exception("Authentication failed");
                }

                Console.WriteLine("Comet username and password are: {0}:{1}", username, password);
                CometClientIdentity identity = new CometClientIdentity(username);
                identity.Password = password;
                CometClientPrincipal principal = new CometClientPrincipal(identity);
                _user = principal;
                if (CometServer.Authenticate != null && !CometServer.Authenticate(_user))
                {
                    throw new Exception("Authentication failed");
                }

                Console.WriteLine("HashSetting up comet connection");

                // setup comet client
                //WriteOKResponse();

                _cometId = CometServer.GenerateCometId();
                Console.WriteLine("HashSetting comet id to: {0}", _cometId);
                CometServer.AcceptClient(this);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception was thrown: {0}", e);
                _context.Close();
                throw e;
            }
        }
Пример #2
0
 public CometClientPrincipal(CometClientIdentity identity)
     : base(identity, null)
 {
 }