A
andy.dreistadt
Hi all,
I was wondering if anyone has used the isReachable() method from the
InetAddress class and could help me with a problem I'm having. Here's
the situation:
I'm creating an InetAddress as shown below and checking to see if each
IP is reachable. Earlier I thought that this method was a kind of
"ping" and until now it has acted that way.
//Check to see if each device is connected
isReachable = new boolean[gtps.size()];
for (int i = 0; i < gtps.size(); i++)
{
InetAddress temp_addr = (InetAddress)IP_addresses.get(i);
try
{
isReachable = temp_addr.isReachable(2000);
System.out.println("isReachable[" + i + "]: " + isReachable);
}
catch(IOException e)
{
JOptionPane.showConfirmDialog(null, "NetInterface " +
(String)Names.get(i) + " could not be found.", "Invalid IP",
JOptionPane.DEFAULT_OPTION);
}
if (!isReachable)
{
removeIP(i);
}
}
When I run this code when the IP devices are connected, the isReachable
will return true. If they are disconnected, the value becomes false
(which is what made me believe this is some sort of ping function).
However, when I disconnect my computer from the network that the IP
values are on, isReachable will return true. Is there something
conceptually that I am missing about the method? I have considered the
fact that isReachable will return true if a device at that IP _could_
be reached even though it doesn't exist, but then disconnecting the
network should return false, right?
Any help in this matter would be greatly appreciated.
Thanks in advance,
Andy
I was wondering if anyone has used the isReachable() method from the
InetAddress class and could help me with a problem I'm having. Here's
the situation:
I'm creating an InetAddress as shown below and checking to see if each
IP is reachable. Earlier I thought that this method was a kind of
"ping" and until now it has acted that way.
//Check to see if each device is connected
isReachable = new boolean[gtps.size()];
for (int i = 0; i < gtps.size(); i++)
{
InetAddress temp_addr = (InetAddress)IP_addresses.get(i);
try
{
isReachable = temp_addr.isReachable(2000);
System.out.println("isReachable[" + i + "]: " + isReachable);
}
catch(IOException e)
{
JOptionPane.showConfirmDialog(null, "NetInterface " +
(String)Names.get(i) + " could not be found.", "Invalid IP",
JOptionPane.DEFAULT_OPTION);
}
if (!isReachable)
{
removeIP(i);
}
}
When I run this code when the IP devices are connected, the isReachable
will return true. If they are disconnected, the value becomes false
(which is what made me believe this is some sort of ping function).
However, when I disconnect my computer from the network that the IP
values are on, isReachable will return true. Is there something
conceptually that I am missing about the method? I have considered the
fact that isReachable will return true if a device at that IP _could_
be reached even though it doesn't exist, but then disconnecting the
network should return false, right?
Any help in this matter would be greatly appreciated.
Thanks in advance,
Andy