There is a way to measure latency network in java(有一种方法可以在 java 中测量延迟网络)
问题描述
我正在使用一个简单的程序,一开始我将在所有 MAN 主机上执行 ping 操作,以验证是否所有主机都在线(完整),但我想实现一些测量主机之间延迟的方法.有没有办法做到这一点?有什么建议吗?
I'm working in a simple program, for beginning i will ping in all MAN hosts to verify if all hosts are online (complete) but i want implement some way that measure latency between hosts. Is there any way to do that? Any tips?
无论如何,谢谢
推荐答案
您可以保留 ping 和 pong 打包的时间戳,并简单地计算两者之间的差异两个.
You can keep a timestamp for the ping and the pong packed and simply compute the difference between the two.
根据定义,延迟
您可以多次重复该过程以计算其他指标,例如抖动.
You can repeat the process more that one time to compute other metric, such as the jitter.
以下简单的东西应该可以达到目的.
Something simple as the following should serve the purpose.
while (sentPacket < MAX_PACK_NUM) {
// Timestamp in ms when we send it
Date now = new Date();
long msSend = now.getTime();
....
//send ping
socket.send(ping);
//receive ping
socket.receive(response);
now = new Date();
long msReceived = now.getTime();
// Print the packet and the delay
long latency= msReceived - msSend;
++sentPacket;
}
这篇关于有一种方法可以在 java 中测量延迟网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有一种方法可以在 java 中测量延迟网络
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
