Пример #1
0
 private void Authenticate()
 {
     byte[] buffer = new AuthRequest(this.Username, this.Password).Serialize();
     this.stream.Write(buffer, 0, buffer.Length);
     buffer = new byte[2];
     this.stream.Read(buffer, 0, 2);
     if (!AuthResponse.Deserialize(buffer).Success)
     {
         throw new Socks5Exception("Authentication failed.");
     }
 }
Пример #2
0
        /// <summary>
        /// Performs Username/Password authentication.
        /// </summary>
        /// <exception cref="Socks5Exception">The server returned invalid or
        /// unexpected data, or authentication failed.</exception>
        void Authenticate()
        {
            byte[] bytes = new AuthRequest(Username, Password).Serialize();
            stream.Write(bytes, 0, bytes.Length);
            // Read the server's response.
            bytes = new byte[2];
            stream.Read(bytes, 0, 2);
            AuthResponse response = AuthResponse.Deserialize(bytes);

            if (!response.Success)
            {
                throw new Socks5Exception("Authentication failed.");
            }
        }