Пример #1
0
        /// <summary>
        /// Sends a request to the server to verify a user token is valid.
        /// </summary>
        /// <param name="token">Token to verify</param>
        /// <returns>True if the token is valid</returns>
        public bool VerifyToken(UserToken token)
        {
            TokenVerifyRequest request = new TokenVerifyRequest(token);
            object             reply;

            using (TcpClient client = new TcpClient()) {
                client.Connect(serverEndPoint);
                NetworkStream networkStream = client.GetStream();

                Message.Send(networkStream, request);
                reply = Message.Recieve(networkStream);
            }

            if (reply == null)
            {
                throw new Exception("BBRequest Error: Expected reply but recieved none");                //Console.Error.WriteLine("BBRequest Error: Expected reply but recieved none");
            }
            else if (!(reply is TokenVerifyResponse))
            {
                throw new Exception("BBRequest Error: Expected VerifyTokenResponse but recieved unknown response type");
            }
            else
            {
                return(((TokenVerifyResponse)reply).valid);
            }
        }
Пример #2
0
        /// <summary>
        /// Sends a request to the server to verify a user token is valid.
        /// </summary>
        /// <param name="token">Token to verify</param>
        /// <returns>True if the token is valid</returns>
        public bool VerifyToken(UserToken token)
        {
            TokenVerifyRequest request = new TokenVerifyRequest(token);
            object reply;

            using (TcpClient client = new TcpClient()) {
                client.Connect(serverEndPoint);
                NetworkStream networkStream = client.GetStream();

                Message.Send(networkStream, request);
                reply = Message.Recieve(networkStream);
            }

            if (reply == null)
                throw new Exception("BBRequest Error: Expected reply but recieved none");//Console.Error.WriteLine("BBRequest Error: Expected reply but recieved none");
            else if (!(reply is TokenVerifyResponse))
                throw new Exception("BBRequest Error: Expected VerifyTokenResponse but recieved unknown response type");
            else
                return ((TokenVerifyResponse)reply).valid;
        }