views:

19

answers:

1

Something I am playing with at the moment is a Rest / HTML page that dynamically updates via JSON calls.

Now in the case that I want this to run on as low a bandwidth as possible.

So if the server is shut down, then booted up again I want the updates to continue again in most cases this works some cases parts of the javascript won't work and it times out.

So what is a low overhead solution to detect that the Server has started up again?

(Looking for good ideas or other methods to do this)


thoughts:
So far I have thought of having a status request but this uses bandwidth again to continually run?

Or how to only run this status request once the server had gone down and stop when its up?

+2  A: 

You could use the setInterval function to continuously poll the server for updates. Once a request fails you could enter a so called safe-mode by sending only HEAD requests (and as suggested by @sje397 also increase the timeout interval) to reduce bandwidth and once it succeeds you enter again normal mode and continue with GET/POST.

There are also more exotic things like COMET and Web Sockets in HTML 5 that allow the server to push updates to the client.

Darin Dimitrov
While it is a working solution, it will continually run in the background using more data. +1 for the fact setInterval will not be cancelled as it is only running itself.
Thqr
You'd probably want to increase the time between polls up to some reasonable limit also.
sje397
As Nice as Web Sockets are, not everything can use them. Currently I am just sending "GET" requests for the JSON strings.
Thqr
+1 for Reasonable time limit. If it is a page that updates every 1-3Sec, and possibly could lose connection once a day? What would you deem to be a reasonable limit. 60sec as it needs to be updating but not often enough to use much data let alone a JSON string containing {"Status":"Good"}
Thqr
@sje397, good point about increasing the timeout between polls. I've updated my answer to include this information.
Darin Dimitrov