Click to See Complete Forum and Search --> : Detecting status of remote server


geuis
05-14-2003, 01:24 PM
I am trying to build a new tool for a website that will automatically check to see if a remote server is up and running.
I was thinking I could do this through javascript somehow, so that everytime the page is loaded, it will automatically check to see if the other server is available.
Depending on if the server is up or down, the script will update the webpage with its current status.
I am wondering what function of javascript I could use to do this. If javascript won't work, I'm also wondering if maybe I could do it with a PERL script, though I acknowledge I may not get an answer to that in this forum.

Thanks for any help!

Jona
05-14-2003, 01:26 PM
It may be possible if you use frames.

AdamBrill
05-14-2003, 04:50 PM
You should be able to do it something like this:<HTML>
<head>
<script language=javascript type="text/javascript">
theVar=false;
function go(){
if(theVar){
//file exists...server is up
}else{
//file doesn't exist...server is down
}
}
</script>
<script language=JavaScript src="script.js" type="text/javascript" onload="go()"></script>
</head>
<body onload="setTimeout('go()',3000);">
</body>
</HTML>

Then put this in the external file(script.js):theVar=true;
Link to the external file with an absolute path, and it will wait 3 seconds to see if it will load. If it will, it runs the //file exists part; if not, it will run the //file doesn't exist part. I hope that helps! :)

geuis
05-14-2003, 05:07 PM
Thanks for the suggestions. If I can get it to work, I will try to use them. I probably should have been more precise to say that the server is not a webserver. There is an open source game myself and some others are developing. I am trying to add a function to the game website that will let visitors know if the game server is up or down. The game is still in alpha, so we are still experiencing some problems here and there as the server relocates or is down from time to time. That's kind of why I was thinking I might be able to do it in PERL, but perhaps not javascript, but I wanted to check anyway.
Still, if it can be done in javascript, I would love to know how or at least be pointed in the right direction.

Charles
05-14-2003, 05:21 PM
Something like this might do the trick. Just be aware that one in ten users do not use JavaScript, so make sure that the page "fails safe" for those good people.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
var img = new Image();
img.onload = function () {alert('Server is up and running.')}
img.onerror = function () {alert('Server appears to be off line')}
img.src = 'http://forums.webdeveloper.com/images/profile.gif';
// -->
</script>