Check out the java.net.InetAddress.isReachable method; it's pretty close to a ping.
What are you planning to use this information for? I'm asking because -generally- the more interesting information is whether there's a process listening on a particular port of some machine, than to know whether the machine itself is up.
And if the specified site is down at the time, it takes more time to fetch the specified file. So to avoid this.
I need to check whether the site is up or down before trying to fetch the files.
As you said i tried using inetAddress.isReachable() it supports only for hostNames.
However it is useful for me. But i have to check using the URL, for ex: 'https://192.xx.xx.xxx/util.js'
Hope you could understand my issue.
Joined: Mar 22, 2005
So it is indeed like what I said - you're interested in whether the HTTP server is running, not whether the machine is up?
Judging by the "192.xxx" address this is a machine on the same network, or a network close by, so the connection should be pretty fast. That means you can set the timeout for failure pretty short (maybe 10 seconds, or even 5).
Joined: May 23, 2008
Absolutely right Ulf. I need to know whether the HTTP server is running or not, not the machine.
This is on different network.
How to set the timeOut. If suppose the HTTP server responds slowly due to heavy load or slow network connectivity. How to handle this situation.
how to set the timeOut function in this case.
Do not hesitate if my questions are like baby step.
Joined: Mar 22, 2005
How to set the timeOut.
Check out the HTTPUrlConnection.setConnectTimeout and setReadTimeout methods.
If suppose the HTTP server responds slowly due to heavy load or slow network connectivity. How to handle this situation.
It's impossible to differentiate between a really slow server or an unreachable server in general. You could play around with different connection timeouts vs. read timeouts. I think if the server is just slow, you'd time out on the read, while if the server is not up at all, you'd time out on the connection.