InetAddress: isReachable(int timeout) : InetAddress « java.net « Java by API






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");
    }
  }
}

           
         
  








Related examples in the same category

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