我需要计算以下内容:
有人可以告诉我跟踪这些事情的最佳方式是什么?
我需要准确度才能高。
答案 0 :(得分:4)
请找到获得延迟的代码。如果它解决了您的问题,请将其标记为解决方案,以便帮助对方找到答案。
public String getLatency()
{
String latency ="";
String ip = "ip address of the server";
String pingCmd = "ping -c 25 " + ip;
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine;
String latencyResult = null;
while ((inputLine = in.readLine()) != null)
{
latencyResult = inputLine;
}
String[] keyValue = latencyResult.split("=");
String[] value = keyValue[1].split("/");
latency = value[1];
}
catch (Exception e)
{
LogWrite.d(TAG, "Exception..."+e);
}
return latency ;
}`