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
If you are talking about running something client side, I am not sure this is possible due to security reasons.
Maybe your best bet would be a java applet - but again this needs to be checked against local security policy.
If I try to think about some hack in JS to do this, maybe you can try to send an async request with a callback function which measures the milliseconds it took - but this is just off the top of my head.
Here's an <iframe>
approach:
(source: magnetiq.com)
Create a table (not necessarily in the literal <table>
sense) with two columns. The first column will hold the name of servers (and possibly links to them). The second column has iframes that load probe documents from the respective servers. Each probe document does this on the initial fetch request:
You'd be using iframes without infringing the same-domain policy because there's no attempt at manipulating the iframe contents at all. The player will simply see the values with his/her own eyes and you'll rely on the user glancing at the numbers and clicking on the server link that makes the most sense.
All you really need is the time from the connection start, to the time of the first readystate change...
function getPing() { var start; var client = getClient(); // xmlhttprequest object client.onreadystatechange = function() { if (client.readyState > 0) { pingDone(start); //handle ping client.onreadystatechange = null; //remove handler } } start = new Date(); client.open("HEAD", "/ping.txt"); //static file client.send(); } function pingDone(start) { done = new Date(); ms = done.valueOf() - start.valueOf(); alert(ms + "ms ping time"); } function getClient() { if (window.XMLHttpRequest) return new XMLHttpRequest(); if (window.ActiveXObject) return new ActiveXObject('MSXML2.XMLHTTP.3.0'); throw("No XMLHttpRequest Object Available."); }