File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check server is up ?

 
raj varma
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
raj varma
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tarun Trehan
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
 
Rashmi Savlgi
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Michael Morris
[ February 09, 2003: Message edited by: Michael Morris ]


HI,

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.

 
Tarun Trehan
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One simple example is stated in a post Ping Server For Status & Action
I had to monitor services on my blog i.e. whether it is responding or not.
Hopefully it will help you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic