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 @Value 注解中正确指定默认值? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 从 python 访问 JVM 2022-01-01