?
Solved

Java method isReachable is not working %100 of the time

Posted on 2007-03-22
11
Medium Priority
?
2,240 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

807 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