Tien Shan wrote:Hi!
I am trying to find if a server is alive or not using java:
Rob Spoor wrote:You could try InetAddress and its isReachable method. It's not guaranteed to work though.
Rob Spoor wrote:You should only use URLConnection if the service is supported by java.net.URL. If it can be any kind of service using the Socket is better, as it has no dependencies - it can connect to any port on any machine, as long as the network allows this.
Tien Shan wrote:
Jeff: Come on, don't be so hard on me
What I mean:
I have a service running at a server on a certain port.
(1) the host machine is powered off
(2) I can reach the server, and the port is open, but the service is not running
(3) it takes too much time to connect. this could be network traffic issues ( server and service may have been available if I were local, but I am always checking it from far away, different domain)
I think that covers my requirements.
I am designing a system whose task is to check if a service is available on a particular server. And if it takes a long time (and times out on me, if not up and running or says 'ok I am alive' after a long, long time), it is not acceptable.
I cannot wait more than *some commonly accepted value* seconds.
I don't know how to settle on this "some commonly accepted value". If you were to design Google's login system, for example, how much time would you set before you display a message like "server is not available now.. please try again later" kind of message?
Tien Shan wrote:Rob, I don't know if the service in question is supported. I will check (=google) the documentation. The service I will be using is called CAS, the Central Authentication Service. You may have heard about it or may have even used it.