import java.net.*; import java.io.*; public class TimeIsReachableTest { public static void main(String args[]) { if(args.length != 3) { System.out.println("Usage: java ReachableHostTest "); System.exit(1); } InetAddress hostnames[] = new InetAddress[2]; String tempStr = null; for(int i=0; i<2; i++) { try { tempStr = args[i]; hostnames[i] = InetAddress.getByName(tempStr); } catch (UnknownHostException e) { System.err.println("UnknownHostException thrown. Test failed."); System.err.println("The unknown host is : " + tempStr); e.printStackTrace(); System.exit(1); } } int timeout = Integer.parseInt(args[2]); try { long startTime = 0; long endTime = 0; System.out.println("Timeout for isReachable() is set to " + timeout); startTime = System.currentTimeMillis(); boolean isReach_1 = hostnames[0].isReachable(timeout); endTime = System.currentTimeMillis(); System.out.println("isReach_1: " + isReach_1 +", time= " + Long.toString(endTime-startTime) + " ms"); startTime = System.currentTimeMillis(); boolean isReach_2 = hostnames[1].isReachable(timeout); endTime = System.currentTimeMillis(); System.out.println("isReach_2: " + isReach_2 +", time= " + Long.toString(endTime - startTime) + " ms"); } catch (IOException e) { System.err.println("IOException occured."); e.printStackTrace(); System.exit(1); } } }