Click to See Complete Forum and Search --> : Am I in the right area!??!?!


mike-ay
02-14-2003, 05:20 AM
Hellooo

I'm pretty new to all this, so I'm not quite sure if this request falls under Javascript, DHTML or whatever (though you're all smart cookies, you'll probably know *wink*).

I am designing a site at the moment that links to two servers. What I would like to do is have a message on the website to say whether the servers are available or not.

Is there something that can ping the server (or something else that can tell if they're working - then come back with an "available" or "unavailable" depending on the response from the server???

Does this make any sense at all??? :confused:

Hmmmm...

Thanks for listening :)

khalidali63
02-14-2003, 05:47 AM
If you are not making use of any other hard core programming languages such as java,then there is a hack one can try to implement.

try this link.

http://68.145.35.86/skills/javascripts/FindOutAServerIsUp.html

cheers

Khalid

gil davis
02-14-2003, 05:51 AM
JavaScript does not have any methods to contact a server.

The only possibility would be to try and load an image from the server and use the onerror event to check for a successful load.

<script>
var server1 = true; // assume server ok
var server2 = true;
var svr1img = new Image();
svr1img.onerror = function () {alert("server 1 is down");server1 = false;}
svr1img.onload = function () {alert("server 1 is up");}
svr1img.src = "http://server1/someimg.gif";
var svr2img = new Image();
svr2img.onerror = function () {alert("server 2 is down");server2 = false;}
svr2img.onload = function () {alert("server 2 is up");}
svr1img.src = "http://server2/someimg.gif";
</script>

mike-ay
02-14-2003, 06:02 AM
Fantastic - thank you both :)