Solved

Java method isReachable is not working %100 of the time

Posted on 2007-03-22
11
1,866 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
Comment Utility
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
Comment Utility
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
Comment Utility
same problem

Also note that i can ping these systems
0
 
LVL 86

Expert Comment

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

Author Comment

by:bbcac
Comment Utility
what proxy though... we use a proxy for our website, these servers are all internal to our network
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>what proxy though.

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

Expert Comment

by:mayankeagle
Comment Utility
>> 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
Comment Utility
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
Comment Utility
If the servers that fail may have several IP addresse, try using  InetAddress[] getAllByName(String host)  instead.
0
 
LVL 30

Expert Comment

by:mayankeagle
Comment Utility
>> 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:
mayankeagle earned 250 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
bunnyEars challenge 6 62
mapBully challenge 6 88
Core Java. What output will be and why ? 6 57
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now