BlottoBeats.Library.Networking.BBServerConnection.VerifyToken C# (CSharp) Method

VerifyToken() public method

Sends a request to the server to verify a user token is valid.
public VerifyToken ( UserToken token ) : bool
token BlottoBeats.Library.Authentication.UserToken Token to verify
return bool
        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;
        }