InetAddress IsReachable() Example

Test whether that address is reachable.


InetAddressclass IsReachable() method example. This example shows you how to use IsReachable() method.This method Test whether that address is reachable.

Here is the code:-
/* 
 * @Program that Test whether that address is reachable.
 * IsReachable.java 
 * Author:-RoseIndia Team
 * Date:-19-Jun-2008
 */

import java.net.*;
public class IsReachable {
public static void main(String[] argsthrows UnknownHostException{
  try {

      int timeout = 2000;
      InetAddress[] addresses = InetAddress.getAllByName("girish-desktop");
      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");
    }
  }
    }

Output of the program:-
 girish-desktop/127.0.1.1 is reachable

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US