Solved

Java method isReachable is not working %100 of the time

Posted on 2007-03-22
11
1,918 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 39
split53 challenge 7 80
JDeveloper 12c for 32 bit 4 71
Arrays.asList  VS  ArrayList 4 45
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

863 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

27 Experts available now in Live!

Get 1:1 Help Now