Forum: Ruby on Rails AJAX : Server to Client callback possible ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5374b14d364988d824b3f7f5c3c6625d?d=identicon&s=25 olivier Hericord (Guest)
on 2005-12-23 17:47
(Received via mailing list)
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
70d14478017f13972bb6d82a5dcf161f?d=identicon&s=25 Toby Boudreaux (Guest)
on 2005-12-23 18:14
(Received via mailing list)
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.
29c5380dd7c19eebebf03bc050c7e27d?d=identicon&s=25 Geoff Hopson (Guest)
on 2005-12-23 19:29
(Received via mailing list)
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 :-)

Good luck,
Geoff
C7407d9ae305656e88bc7935d4af9cbd?d=identicon&s=25 Jeff de Vries (Guest)
on 2005-12-23 19:48
(Received via mailing list)
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 ...
8c7a98649cdbbdf39eeed17ca9bdbbd3?d=identicon&s=25 Josh Charles (Guest)
on 2005-12-23 20:12
(Received via mailing list)
On 12/23/05, Jeff de Vries <jdevries@pfrog.com> 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.
D2b2017098da3e2fd1cdcfbb72ecdbfb?d=identicon&s=25 Jason Edgecombe (Guest)
on 2005-12-23 20:24
(Received via mailing list)
Josh Charles 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
This topic is locked and can not be replied to.