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 中测量延迟网络


- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01