Java API Tutorial - Java InetAddress.isReachable(int timeout)








Syntax

InetAddress.isReachable(int timeout) has the following syntax.

public boolean isReachable(int timeout)   throws IOException

Example

In the following code shows how to use InetAddress.isReachable(int timeout) method.

import java.net.InetAddress;
//from ww w  .ja  v a  2  s. co  m
public class Main {
  public static void main(String[] argv) throws Exception {
    InetAddress address = InetAddress.getByName("web.mit.edu");
    System.out.println("Name: " + address.getHostName());
    System.out.println("Addr: " + address.getHostAddress());
    System.out.println("Reach: " + address.isReachable(3000));
  }
}

The code above generates the following result.