Solved

Java method isReachable is not working %100 of the time

Posted on 2007-03-22
11
1,975 Views
Last Modified: 2008-04-14
I have a method that checks if a computer is online. IT works most of the time but sometimes it falsely says that computers are in connected.

I need to add to it so that it is more thourough. It is also important to note that it is always the same systesm that reported incorrectly. I suspect, based on the java docs, the the isReachable() method is failing due to a firewall or something.
Here is the method:

try{
InetAddress host = InetAddress.getByName(computer);
if (!(host.isReachable(timeoutping))){
notdone = false;
Error = "Communication Error";
}
}catch (Exception e){notdone=false; Error= "Host not found by Name";}
                                    
0
Comment
Question by:bbcac
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 10

Expert Comment

by:Jaax
ID: 18770884
Try running ur program with the proxy and port name set as
java -DhttpProxy.host=yourproxyhost.com -DhttpProxy.port=yourproxyport yourJavaClass
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18771489
More reliable will be to connect to a service that you know to be running, especially since that's normally why one's interested in the first place
0
 

Author Comment

by:bbcac
ID: 18771603
same problem

Also note that i can ping these systems
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 18771636
If you're connecting thru a proxy, IT needs to be reachable as well as the true destination
0
 

Author Comment

by:bbcac
ID: 18772145
what proxy though... we use a proxy for our website, these servers are all internal to our network
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18772471
>>what proxy though.

Sorry - possibly got misled by the second comment ;-)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18772627
>> I suspect, based on the java docs, the the isReachable() method is failing due to a firewall or something.

You don't have a firewall inside your company do you? I mean the systems within your system should be reachable and within the same company firewall. If it is blocked by the firewall, it won't work even a single time but looks like you said it works sometimes.

Probably try increasing your timeoutping value and see if there is a difference.
0
 

Author Comment

by:bbcac
ID: 18773096
The timeout is not the issue.  I have increased it many times. It is possible that some servers have certain ports blocked isn't it? Perhaps this is why isReachable is returning false info.

0
 
LVL 20

Expert Comment

by:gatorvip
ID: 18773884
If the servers that fail may have several IP addresse, try using  InetAddress[] getAllByName(String host)  instead.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18774731
>> It is possible that some servers have certain ports blocked isn't it?

You aren't opening a socket to a port so that shoud not be a problem. If you are able tp ping, I guess that host.isReachable () should use the same.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 250 total points
ID: 18774769
http://www.davidreilly.com/java/java_network_programming/#3.5 says that true ping through Java might need JNI.

Also see: http://forum.java.sun.com/thread.jspa?threadID=275511&messageID=3732503

Or try connecting a socket on that remote IP with port number 7.

Otherwise you can try running ping through Runtime.getRuntime ().exec () and read the output:

http://www.exampledepot.com/egs/java.lang/ReadFromCommand.html?l=new
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question