How do I implement a log window in a web browser?
I am interested in adding an HTML / web browser based "log window" to my network device. Specifically, my device has a configured web server and event log, and I would like to keep the web browser window open, for example http: //my.devices.ip.address/system_log , and the events appear as text in the web window -browser as they arise. People can then use this as a quick way to keep track of what the system is doing without having to run special software.
My question is, what's the best way to implement this? I tried the obvious approach: just connect a web server connected to the device via HTTP and TCP and write the required text to the TCP socket when the event occurs, but the problem is that most web browsers (like Safari) do not display the web -page until the server closed the TCP connection, and so the result is that the log data never appears in the web browser, it just acts as if the page was kept forever loading.
Is there some trick to make this work? I could implement it as a Java applet, but I would prefer something lighter / simpler using only HTML or perhaps HTML + JavaScript. Also, I would like the web browser not to poll the server as that would mean too much latency (if there was too much reboot) or load on the system (if the latency was small)
a source to share
Ok, since you say you're ready to do this in javascript:
- You have a continuous recording process without closing the connection.
-
In the client (browser) use the xmlhttp object and track the ready state.
0 = uninitialized 1 = download 2 = loaded 3 = interactive 4 = full
obviously 3 and 4 are what you care about. When you get the output, all you have to do is write the responseText to the div and you are set. Look here for properties and usage of xmlhttpobject.
a source to share
If you don't want to use a poll, you are more or less stuck writing your log viewer completely outside of the browser. However, it is fairly straightforward to write your own survey that does a great job of minimizing both latency and system load (as you mentioned the issues).
The trick is to use Comet , which is essentially Ajax + long polling.
a source to share