InetAddress: isReachable(int timeout)


import java.io.IOException;
import java.net.InetAddress;

public class MainClass {
  public static void main(String[] args) throws IOException {
    try {

      int timeout = 2000;
      InetAddress[] addresses = InetAddress.getAllByName("www.java2s.com");
      for (InetAddress address : addresses) {
        if (address.isReachable(timeout))
          System.out.printf("%s is reachable%n", address);
        else
          System.out.printf("%s could not be contacted%n", address);
      }
    } catch (Exception e) {
      System.out.printf("Unknown host: %s%n", "www.java2s.com");
    }
  }
}
Home 
  Java Book 
    Networking  

InetAddress:
  1. InetAddress
  2. InetAddress: getAllByName(String name)
  3. InetAddress: getByName(String host)
  4. InetAddress: getCanonicalHostName()
  5. InetAddress: getHostAddress()
  6. InetAddress: getHostName()
  7. InetAddress: getLocalHost()
  8. InetAddress: isReachable(int timeout)