Skip to main content
gamedev.net
🔒 Locked

JavaScript: Pinging A Server

Started by Estauns Jan 22, 2005 at 9:04 PM 3 replies 350+ views
Original Post
Estauns
Estauns
Is there a way to ping a server through &#106avascript? I can't find anything on Google, so I'm assuming it's not possible, but thought I'd ask anyway.
"Where genius ends, madness begins."Estauns
Nice Coder
Nice Coder
It just might be possible.
Resonable, maybe not, but possible, yes.

What you need to do, is to make a frame, that then connects to your PHP script, which then pings the adress, along with a bit of &#106avascript to get the info back to you.<br><br>From,<br>Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Kylotan
Kylotan
Do you need to do a real ping, or is connecting to a web page on that server enough? I believe you can use things like XMLHttpRequest and the like to at least test the connection. I must admit I don't know anything about this approach however.
markr
markr
You're not going to be able to do any low-level networking in &#106avascript in a browser. But as Kylotan says, you could use XMLHttpRequest to request a small item from the server and time it. That might do what you want.<br/><br/>Or if you genuinely feel the need to do a ping, you could use a XMLHttpRequest to request a server-side script, which would do a genuine ICMP ping, but from the server. So then the time you get will be not dependent on the time from the client to the target, but the server.<br/><br/>If you're trying to time various servers to determine which one is nearer, the XMLHttpRequest for a small file should do the job. But it's not terribly accurate as it will be affected by other things like network traffic, server load etc. And the time that you get will be for the entire request not just one round trip, so packet loss could increase that considerably (as HTTP uses TCP).<br/><br/>Mark

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.