AJAX : Server to Client callback possible?

hi,

is there a way (with rails) to have live updates triggerred by the
server on the client side?
is there a little javascript lib i didn’t know that can listen to
incoming server orders…

a friend of mine thought about an hidden .swf to make the socket
connection and that can launch javascript instructions into the client
web page.

any working solutions to point me to ?

thanks

There is no interrupt model for Javascript – you’re stuck with polling
(timed XmlHttpRequests), which is far from efficient or elegant.

A SWF opening a socket is how I would handle this sort of scenario. Your
onData (etc) callback in the SWF can call JS as needed.

In Java land I use something called ‘pushlets’ to achieve this - it
basically opens up a connection to the web server and keeps the
connection
open so that the server can stream info back up to the client. Works
great.
Javascript on the client manages the connection, the XML content etc.

The project is opensource, so make a name for yourself and convert it or
jruby it or something :slight_smile:

Good luck,
Geoff

Just a thought, but couldn’t you make an AJAX call back to the server,
and the server, instead of replying right away, waits until an event
happens and then replies to the AJAX request? This gets the “open
connection waiting for an event” and lets you stay in ruby/rails
(assuming you can wait on the reply like that without adverse effects on
the server).

I think for this to work you’d have to unhook the AJAX call from being
tied to a particular button/link (like how rails does it), and instead
make the AJAX call as part of the page onLoad handler, so it could be
listening in the background. You’d also need a way to start a new AJAX
request after you received each event.

Sounds like it could work …

On 12/23/05, Jeff de Vries [email protected] wrote:

Just a thought, but couldn’t you make an AJAX call back to the server,
and the server, instead of replying right away, waits until an event
happens and then replies to the AJAX request? This gets the “open
connection waiting for an event” and lets you stay in ruby/rails
(assuming you can wait on the reply like that without adverse effects on
the server).

I thought about this, but you might face a browser or server timeout
error.

Josh C. wrote:

I thought about this, but you might face a browser or server timeout error.

what about using periodically_call_remote? call the server every 30
seconds or so. the server would only hold the connection open for 29.5
seconds. The client would reestablish the connection every x seconds.

call