Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
Aug 21, 2006

WEBINAR:

On-Demand

Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js


Ping with J2SE 1.5.0

The following code shows you how to simulate the "ping" command with the J2SE Tiger InetAddress.isReachable method.

import java.io.*;
import java.net.*;

public class reachable{
  public static void main(String args[]) {
  String[] addrs=        
        {"www.java.sun.com","www.yahoo.com","www.google.com"};
    try{
       for(int i=0;i<addrs.length;i++)
               {
               InetAddress addr=InetAddress.getByName(addrs[i]);
               System.out.println("Name:"+addr.getHostName());
               System.out.println("Addr:"+addr.getHostAddress());

               //the address will be checked for 5005 miliseconds
               System.out.println("Reach:"+addr.isReachable(5005));
               }
           }catch(UnknownHostException e){           
              System.out.println(e.getMessage());
           }catch(IOException e){
              System.err.println(e.getMessage());
         }
     }
   }
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date