Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6032857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:23:51+00:00 2026-05-23T05:23:51+00:00

I would want to use resolved IP address to connect to server instead of

  • 0

I would want to use resolved IP address to connect to server instead of hostname. Here is my code snippets:

     // Get domain name from URL
    String domainName = url.substring("http://".length(),
            url.indexOf("/", 8));
    // Get IP address as string
    InetAddress inet = null;
    try {
        inet = InetAddress.getByName(domainName);
    } catch (UnknownHostException e) {
        Log.i(TAG, "The IP address cannot be resolved for " + domainName);
    }
        resolvedIP = inet.getHostAddress(); 

Here i’m able to successfully get IP ADDRESS. Now i try to replace my url as below:

url = url.replace(domainName, resolvedIP);

Now I connect to server:
URL download = new URL(url);


conn = (HttpURLConnection) url.openConnection();

conn.getInputStream(); //Throws IO Exception

I’m able to successfully connect if I use URL as it is (without replacing domain name with IP Address).

Please let me know if I’m doing things correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:23:52+00:00Added an answer on May 23, 2026 at 5:23 am

    As a general rule, try to use the hostname-based URL. It is not uncommon to have multiple web sites on the same IP, distinguished only by the site name (so-called virtual hosting). What you are doing will only work for the case where there is a single site on a given IP.

    It’s quite common for load-balancers to have one IP for each “site” it balances, but there’s still no guarantee that you will connect to the same backend for two consecutive requests. However, there are web load balancers that extend the use of virtual hosting all the way to the load-balancing layer.

    I would simply try to stick downloading by a hostname-based URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please explain when would I want to use delegation instead of inheritance?
I'm building a web application and eventually would want to use Yii framework. But
Executor seems like a clean abstraction. When would you want to use Thread directly
I want to use XMPP to push data to my client which would translate
I want to use libharu to render my documents to PDF. I would like
I want to use the sharer.php popup to open the share dialog, but would
I want to use a shape of some sort for now, but would like
Which version of Linux would be my best choice if I want to use
I would like to reproduce UIScrollView's flick-to-scroll behavior, but I don't want to use
I would like to use Parsec's makeTokenParser to build my parser, but I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.