Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

Anyway, thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
171 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can keep a timestamp for the ping and the pong packed and simply compute the difference between the two.

This is by definition, latency

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;
         }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...