2014年3月10日 星期一

Ping

Ping指令使用方法如下:


// -c : the times for execute ping.
// -w : timeout to wait for ping response
Process p = Runtime.getRuntime().exec("ping -c 1 -w 10 www.google.com");
// send 1 packet to "www.google.com", waiting for response in 10 seconds.
if(p.waitFor() == 0) {//blocking 
 //ping succeeded
 ...   
}
else {
 //ping failed
 ...   
}


沒有留言 :

張貼留言