Check host availability

T

test2000

Hello

I'm trying to write a javascript that checks if a server/host is
available. To be more precice. I would like to check if the browser can
read an XML file from a server. If not the script should read the same
XML file from a backup server.

Does anyone have any idea how to achive that??

Any help is appreciated.

Thanks

Andy
 
E

Erwin Moller

Hello

I'm trying to write a javascript that checks if a server/host is
available. To be more precice. I would like to check if the browser can
read an XML file from a server. If not the script should read the same
XML file from a backup server.

Does anyone have any idea how to achive that??

Any help is appreciated.

Thanks

Andy

Hi,

You could use an Ajaxoid approach.
Try a httpxmlrequest-like thing, and check for errors when it returns.
for starters: www.w3schools.com, and select Ajax.

However, I think a serverside approach (eg PHP) would be easier if that is
an option for you.

Regards,
Erwin Moller
 
P

pcx99

Hello

I'm trying to write a javascript that checks if a server/host is
available. To be more precice. I would like to check if the browser can
read an XML file from a server. If not the script should read the same
XML file from a backup server.

Well first, that server/host is going to have to be in the same domain
as the web page itself. If you can get the web page you should be able
to get the data right? If you're thinking of having a webpage on
"mydomain.com" and wanting it to check/pull data from
"overtherainbow.org" it isn't going to happen, the browser security
model will not allow that to happen.

However if your web page is www.mydomain.com and www.mydomain.com/data/
is mapped to a different server then there are several possibilities.

The best approach is to have your web server monitor the status of your
data server since it's on the same network and has access to network
tools far more advanced than the browser will give you. Here it's a
simple task to have the browser do an ajax request to the web server and
get the status of the data server transmitted back.

If you need the browser to do the check then things are slightly more
sticky. You'll need to use ajax again to call the data server and then
check the response codes. You'll get nearly instant replies if the
data server is up but refusing connections, but if the server is down it
will take a very long time for the ajax request to time out and throw an
error.

In either case you will be using ajax, just do a search on "ajax
tutorial" on google and you'll find a few good ones.
 
M

Mike.Duffy

(e-mail address removed) wrote in 79g2000cws.googlegroups.com:
I'm trying to write a javascript that checks if a server/host is
available. To be more precice. I would like to check if the browser can
read an XML file from a server.

It is easy to check if a GIF file can be served up [1]. If you use the same
server for both, then you can *probably* assume that if the server is up
for GIFs, it is also up for any other files it is hosting.

[1] Use the "onLoad" and "onError" methods of the image object.
 
T

test2000

Mike.Duffy said:
(e-mail address removed) wrote in 79g2000cws.googlegroups.com:
I'm trying to write a javascript that checks if a server/host is
available. To be more precice. I would like to check if the browser can
read an XML file from a server.

It is easy to check if a GIF file can be served up [1]. If you use the same
server for both, then you can *probably* assume that if the server is up
for GIFs, it is also up for any other files it is hosting.

[1] Use the "onLoad" and "onError" methods of the image object.


Thank you very much guys. Your hints were very helpful. I finally
decided for the image solution. very easy indeed and exactly what I
needed...

var myServer = "";
var picServerOne = new Image();
var picServerTwo = new Image();
picServerOne.src =
"http://xxxxxxx.awardspace.com/map/test.gif";
picServerTwo.src = "http://xxxxxxx.50webs.com/map/test.gif";
if (picServerTwo.complete){myServer = "50webs";} // Backup
server
if (picServerOne.complete){myServer = "awardspace";} // Main
server
 
T

tuxedo

(e-mail address removed) wrote:

[...]

You might need to search for a way to prevent the image from getting cached.
 
T

Thomas 'PointedEars' Lahn

var myServer = "";
var picServerOne = new Image();
var picServerTwo = new Image();
picServerOne.src =
"http://xxxxxxx.awardspace.com/map/test.gif";
picServerTwo.src = "http://xxxxxxx.50webs.com/map/test.gif";
if (picServerTwo.complete){myServer = "50webs";} // Backup
server
if (picServerOne.complete){myServer = "awardspace";} // Main
server

Since `complete' is an undocumented proprietary property that does not need
to be supported, myServer will always hold the empty string in other UAs
(e.g. IE). Use the also proprietary, but documented `onload' and `onerror'
event handlers of Image objects instead.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top