InetAddress isReachable()

Discussion in 'Java' started by andy.dreistadt@gmail.com, Feb 10, 2005.

  1. Guest

    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
    , Feb 10, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C
    Replies:
    1
    Views:
    830
  2. vertigo

    IP: long-> InetAddress

    vertigo, May 2, 2004, in forum: Java
    Replies:
    2
    Views:
    4,418
    Roedy Green
    May 3, 2004
  3. Madhur Ahuja
    Replies:
    1
    Views:
    728
    Paul Lutus
    Aug 29, 2004
  4. Roedy Green

    InetAddress.isReachable

    Roedy Green, Mar 23, 2010, in forum: Java
    Replies:
    9
    Views:
    1,431
    Roedy Green
    Mar 27, 2010
  5. sujit
    Replies:
    1
    Views:
    910
    Arne Vajhøj
    Jan 5, 2011
Loading...

Share This Page