This is a discussion on "Ping a server from client PC?" within the JavaScript Forum section. This forum, and the thread "Ping a server from client PC? are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Ping a server from client PC?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Ping a server from client PC?
I've been trying to write a script using AJAX that will ping a foreign server from the client PC and then return the ping time in ms. I'm having no luck; the only time it works is if I'm connecting to a file on the save server, and that's not much use is it? It will almost always return 0.
Could somebody help me out? The servers I will be pinging are my own, so is there something I can do to let the client's browser know I'm pinging a friendly server? I thought of using subdomain DNS, but haven't tested that yet as my current web host is too nasty to let me do that Thanks for any help!
|
|
|
|
||||
|
Re: Ping a server from client PC?
The reason you keep getting 0 is because you haven't defined a callback function... I'm not good at explaining but I hope you get this.
The following line sends the request: obj.send(null);then the code continues to execute line by line before the response is received. meaning this code... ndt = new Date();... is being processed immediately after the request is sent, not when the response is received, which is what you want. What you're missing is what is sometimes called a 'callback' function. That is a function which is executed once the request is complete (the response is received) obj.onreadystatechange = callbackFunctionName;I haven't tested it, it should look like this:
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Last edited by spinal007; Mar 27th, 2007 at 01:52. |
![]() |
| Tags |
| ajax, javascript, ping |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| client mac address or client HDD serial no | uday | JavaScript Forum | 3 | Apr 18th, 2008 23:22 |
| URGENT!!!! Send HTTP request from one web server to another server | chandra.nowduri | ASP.NET Forum | 1 | Aug 7th, 2006 19:18 |
| Difference between Server & Client Scripting | Coty Skaj | Other Programming Languages | 2 | Jul 6th, 2006 17:18 |
| Need to process data on one server, utilize it on another server ... can it be done? | jaobrien | Classic ASP | 1 | Dec 6th, 2005 00:58 |
| Client-Side VS Server Side Scripting | redev2006 | JavaScript Forum | 1 | Jul 30th, 2005 19:30 |