有一种方法可以在 java 中测量延迟网络 [英] There is a way to measure latency network in java

查看:30
本文介绍了有一种方法可以在 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?

无论如何,谢谢

推荐答案

您可以保留 pingpong 打包的时间戳,并简单地计算两者之间的差异两个.

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 中测量延迟网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆