Before connecting to server throgh socket , I want to check whether server is up, as to avoid ConnectException. How do I poll the server to check its status. and When it is up then I will Connect to it ? Please Help.
Hi Raj, Well about the only way to know whether a server is alive or not is thru a ConnectException. You can poll a server with code like this:
This will poll the server every 30 seconds until a connection is established. Note that we only catch the ConnectException and throw all the others back to the calling program. Hope this helps, Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Jan 05, 2003
Hi Michael , Thnax for ur reply, but I am getting exception like ----- Exception in thread "main" java.lang.IllegalMonitorStateException: current threa d not owner at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:426) at TestClient.waitForServerUp(TestClient.java:35) at TestClient.main(TestClient.java:54) --------- I have put wait() method in synchronized block like but it give same exception [/QB]
well I forgot to do synchronized block on notifyall() also.. Now all code is working fine. THANX Michael
Joined: Jan 30, 2002
Hi Raj, Big duhh on me for that one! That's what happens when you don't test code. I forgot to synchronize the waitForServerUp() and timedOut() methods. Just change those two lines thus:
Sorry for the problem, Michael Morris [ February 09, 2003: Message edited by: Michael Morris ]
I am facing a similar situation and found the post useful with clear statement of "Connect Exception" the only way to know if server is up.
However, is it Ok to put some processing/business logic in catch ??
More details on my specific issue at the following link :
Ping Server For Status & Action
Michael Morris wrote:Hi Raj,
Big duhh on me for that one! That's what happens when you don't test code. I forgot to synchronize the waitForServerUp() and timedOut() methods.
Just change those two lines thus:
Sorry for the problem,
[ February 09, 2003: Message edited by: Michael Morris ]
I am new to this forum . I have got a task to write a script to monitor the server status and the services running on it. In case those services go down there should be slert message sent to a particular email id.
I am completely new to Java as I work for Open Text . Can you please help me with it.