Egil said:
Hi Martin
Thanks for the reply. I wasn't aware of the security issues.
It would be easy to make it server side, but that's not really what I
want. I want to allow the users to ping a server (gaming server), so
they can know, how good or bad their connection to it is. Do you see
any way doing this, so it won't be too much of a hazel for the users
(e.g. changing security settings/giving my site special permissions)?
PS. Thanks to Christopher as well for his initial answer.
Given what Martin Honnen said (I assume he's right because I know
nothing of Java and he's a fairly smart guy), if your game server is
also the web server, it sounds like that would satisfy the security
concerns and the applet would be allowed to do the ping or something
like it.
Now, knowing that your end goal is getting some feel for communications
performance between the end user and the server...
If you can't do it in Java, you might consider something *remotely*
similar, like measuring how long it takes to download a file of known
size from the server:
The game server should serve, by FTP or (preferably) HTTP, say... an
image of at least a couple hundred kilobytes. Then, on the host web
page, you could do something like this:
var I = new Image();
I.onload = function () {
T[ 1 ] = Number( new Date() );
// now do something with T[ 1 ] - T[ 0 ]
}
var T = [ Number( new Date() ) ];
I.src = '
http://gamehost.domain.tld/test_image.img?' +
Math.round( Math.random() * 10000 );
The result is a two-element array T containing 0: the time just prior
to telling it to start downloading the image and 1: the time just after
it finished.
So T[ 1 ] - T[ 0 ] = the number of milliseconds between those two
times.
It's not 100% accurate, but then... neither is ping, really. What you
want is for the user to get a *feel* for how it'll go, right?
Of course, you'll need to give them something to measure that against,
so you'll want to be able to say, "this is optimal," "this is
super-fast," "if it's this slow, don't even bother," etc.
I'm sure some other guys here can brush up the code a bit and probably
make it a bit more accurate or cross-compatible, but it's an idea.
Good luck to you.