0

The HTTP connection to a hostname for the first time takes little longer than subsequent requests. Especially, DNS lookup takes long.

I am trying to implement a basic DNS pre-fetcher/resolver using InetAddress or Runtime.getRuntime().exec() in order to improve the HTTP requests performance in ANDROID java without using any third-party library.

Thank you, Niz

Nizzy
  • 1,879
  • 3
  • 21
  • 33
  • So... what exactly is your question/problem statement? And what have you got so far? – MH. Sep 21 '14 at 05:32

1 Answers1

1

Try this. It just determines the ip address of the host from its hostname supplied via String param. Hope it helps you.

public boolean webSiteAvailable(String url) {
try {
    InetAddress ipAddr = InetAddress.getByName(url);
    if (ipAddr.equals("")) {
        return false;
    } else {
        return true;
    }
} catch (UnknownHostException e) {
    e.printStackTrace();
    return false;
}
}
Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
  • Is there anyway to resolve a secure URL, not a host? `https://hostname/path` It's unfortunate that just trying to resolve hostname does not solve my problem. The above code will throw UnknownHostException if you use HTTPS in the URL. So, you can only use hostname without a scheme and a path. – Nizzy Sep 27 '14 at 09:16