Solved

Java method isReachable is not working %100 of the time

Posted on 2007-03-22
11
2,035 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

739 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