webrick refresh on event

R

Roeland Moors

I'm using webrick to display some logging.
The goal is to display a log item as soon as it happens.
But how can I tell webrick to refresh the page?
I can put some html code to refresh every x seconds, but that's
not really what I want.

When creating a servlet I can respond to GET,POST,... requests,
but I want the server to do the refreshing.

Is this possible?
 
D

Dan Fitzpatrick

I'm new to webrick but I think this will work. You can leave the
connection open and pass Javascript to the browser as events happen. You
basically are sending a page that take 10 or 20 minutes to create. After
10 or 20 or 30 minutes or whatever, you can refresh the entire page and
start the loop over.

# output your log framework with the javascript method addLogEvent()
# for each event pass a new javascript block (or simply plain text
appending to the log)
puts '<script type="text/javascript">addLogEvent(...);</script>'

You should add a newline after each Javascript block.

In cgi mode of webrick, you can just print the above javascript blocks
as they happen. Pass a blank event every 30 seconds if the log had no
activity to keep the browser from timing out.

I'm not sure how to do this in servlet mode since it looks like you pass
the complete response to the response handler. But I'm not sure.

Dan
 

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
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top