I run a couple of game tunnelling servers and would like to have a page where the client can run a ping on all the servers and find out which is the most responsive. As far as I can see there seems to be no proper way to do this in JavaScript, but I was thinking, does anybody know of a way to do this in flash or some other client browser technology maybe?
A simple test to measure latency is to run a ping. This is a network diagnostic tool primarily used to test connectivity between two servers or devices. To ping a destination server, an Internet Control Message Protocol (ICMP) echo request packet is sent to that server.
The more common way of measuring latency is called “round-trip time” (or RTT), which calculates the time it takes for a data packet to travel from one point to another on the network and for a response to be sent back to the source.
1. Open a command window by clicking the Windows start button, or hitting the Windows key, and typing in cmd then hitting enter. In the results above, we're looking for the values after time= which shows the latency between your computer and your server in milliseconds(ms).
Most applet technology, including Javascript, enforces a same-origin policy. It may be possible to dynamically add DOM elements, such as images, and collect timing information using the onload event handler.
Psuedo-code
for (server in servers) {
var img = document.createElement('IMG');
server.startTime = getCurrentTimeInMS();
img.onload=function() { server.endTime = getcurrentTimeInMS(); }
img.src = server.imgUrl;
}
Then wait an appropriate time and check the timing for each server object. Repeat as needed and compute averages if you want. I'm not sure what kind of accuracy you can expect.
Disadvantages:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With