I'm trying to find the ping time (using Windows 8, Java 6). I'm using System.currentTimeMillis() method to find a ping time, but it return a strange values. For example when I'm pinging a localhost it returns 1000 ms.
Please help me to create a routine that finds a host ping time.
public int pingHost(String host){
Long start = System.currentTimeMillis();
if (!InetAddress.getByName(host).isReachable(2000)) return -1;
return (int) (System.currentTimeMillis()-start);
}
P.S. This question is not a dublicate of How to do a true Java ping from Windows? It's not enough to me just check the is host online or not. I need to measure the connection speed and find a "ping time" value.