File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes How to check server is up ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to check server is up ?" Watch "How to check server is up ?" New topic
Author

How to check server is up ?

raj varma
Greenhorn

Joined: Jan 05, 2003
Posts: 28
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

Joined: Jan 30, 2002
Posts: 3451
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
raj varma
Greenhorn

Joined: Jan 05, 2003
Posts: 28
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

Joined: Jan 30, 2002
Posts: 3451
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

Joined: Mar 16, 2012
Posts: 49

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

Thanks,
Tarun Trehan (http://allzhere.in)
Rashmi Savlgi
Greenhorn

Joined: Jul 15, 2014
Posts: 1
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

Joined: Mar 16, 2012
Posts: 49

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to check server is up ?