Dumb WebServer Question...

Am I correct in thinking the web server can send a new page to the client at any time and the client (browser) should display it? I use WebServer to provide the UI for my product (auto toolchanger for a CNC milling machine), and when an error occurs, I want to force the browser to display a new page with information about the error. I would just go ahead and try it, but I'm busy with other things right now...

Regards,
Ray L.

Am I correct in thinking the web server can send a new page to the client at any time

No. It can ONLY send a page in response to the client asking for it.

when an error occurs, I want to force the browser to display a new page with information about the error.

No can do.

PaulS:
No. It can ONLY send a page in response to the client asking for it.
No can do.

Is there some clever way to do what I want to do? I know I could set auto-refresh, but that would cause a lot of other problems. If there was, for example, a way for the client to poll a flag in the server, and force a page request when that flag went true, or something like that.

Regards,
Ray L.

Is there some clever way to do what I want to do?

Think about you being the client, and google being the server. Is there some clever way for google to know that you want to search for a particular topic and send you the data before you even ask?

If there was, for example, a way for the client to poll a flag in the server, and force a page request when that flag went true, or something like that.

If the client has to make a request (and it does), it might as well get the whole page.

If the problem is that you are sending "War and Peace' each time, then changes are in order.

I think you're over-looking some things... First, refreshing the page causes an interruption for the user - the page become un-responsive while it's downloading an re-drawing. The user MIGHT be in the middle of doing something, and if he's not fast enough, the page re-draws, and he has to start over. I don't mind booting him when an error occurs, but to have it going on constantly for no good reason, is not acceptable. I just want to have a means of throwing up an alert when something goes wonky on the machine.

While Google does not know what I might want to search for in the future, if an error occurs on their side, they can certainly change what I see. When I'm browsing, I'm constantly seeing the content change, having things pop up, etc. So, there certainly is a way for the server to send new content without re-sending the whole page. I don't mind throwing in a little javascript, or something on that order, if necessary.

Regards,
Ray L.

Unless I'm misunderstanding something, it appears to me a few lines of Ajax can do what I need - make an asynchronous request from the server that does not re-draw the page. The request can request a "file" which need be nothing but the state of the error flag. The javascript can parse the "file" contents, then, if appropriate, force a new page to be loaded, to show the error information.

Regards,
Ray L.

If you want the client to periodically ping the server for new info then JS is perfect.

Most if not all incoming connections from an external server would be blocked (firewall blocks as you didn't ask/request it). The only way you can have a server contacting a client is to add port-forwarding to your client which is a security risk, and a manual operation which a user will have to configure in their router and firewall.

I use JS/ajax in my Ethernet shield projects as I can request one resource at a time manually, rather than using hard coded links in the HTML which the browser tries to grab all at once ( turns out faster in most tests, and avoids too many connections being dropped by the server). Using ajax/JSON you can easily check the status or processing results without disrupting the user.

Also, a tip:

On a mega, you can fit a fair amount of JS/HTML in flash. For example using a modified version of mkfs.py from the esp-ginx project, you can have it gather a folder of files gzip them up and provide a c file with an array of data to send. You just need to send the 'Content-Encoding:gzip' header with the data.

It'll require a small (simple) modification for the AVR & PROGMEM, with my ESP project I use the entire zepto.js, History.js and my own code and it fits in less than 32Kb once gzipped.

Cool! I got it working, with only about 10 lines of javascript/AJAX!

Thanks!

Regards,
Ray L.

"long polling" may be the answer - it means the browser sends a request but the server only responds when it has something useful.

It is part of my EzScrn demo.

...R

Robin2:
"long polling" may be the answer - it means the browser sends a request but the server only responds when it has something useful.

It is part of my EzScrn demo.

...R

AJAX works beautifully, and does exactly what I needed - just a few lines of javascript added to my HTML, and the browser now sends periodic requests, the responses to which can be anything at all. But the user is unaware the polling is occurring, unless an error occurs on the machine. I just have it setup to return one or more key/value pairs that contain "live" data hooked into the main program. So, when the main program changes any of that data to indicate an error, the AJAX script on the browser side can force the page change to occur.

Regards,
Ray L.

The below site has some info on the arduino and dynamic web pages.

zoomkat:
The below site has some info on the arduino and dynamic web pages.

Arduino AJAX Web Server for Reading a Switch Automatically.

That piece of AJAX code is almost identical to what I ended up with, except mine, instead of just displaying the response, parses the response to the Ajax call, and acts on it by conditionally loading a different page.

Regards,
Ray L.

RayLivingston:
AJAX works beautifully,

Long Polling is an AJAX technique. It's purpose is to reduce the number of "poll" requests from the browser if the server does not always have new data. But when the server does have new data it appears to the browser to be delivered immediately.

I'm just suggesting this for your further investigation in case you are interested.

...R

Robin2:
Long Polling is an AJAX technique. It's purpose is to reduce the number of "poll" requests from the browser if the server does not always have new data. But when the server does have new data it appears to the browser to be delivered immediately.

I'm just suggesting this for your further investigation in case you are interested.

...R

Except that, from what I've read, long polling requires server-side support to maintain the connection and keep track of open requests....

Regards,
Ray L.

RayLivingston:
Except that, from what I've read, long polling requires server-side support to maintain the connection and keep track of open requests....

The server needs to be able to respond to another request from the browser while the first request is pending. AFAIK that is a normal feature of servers, although the simple server that is included with Python Bottle web framework does not permit it so I had to tell Bottle to use the CherryPy server.

The most complicated thing was figuring out how to be able to stop Python and the server cleanly with CTRL-C even though there was a pending request.

...R