Reputation: 1889
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
Upvotes: 0
Views: 181
Reputation: 10338
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;
}
}
Upvotes: 1