views:

18

answers:

1

I need to write a Rails application (JRuby) that does asynchronous communication with another service in the background. There needs to be one connection per browser session. (It does not really need to be a open TCP connection but I need to free resources after the session ends.) The communication with the background service is not strict request - response. At any time there can be a message sent from the service to the rails app.

I also need to implement the protocol. How do I do this? Is there a asynchronous framework (e.g. like Twisted or Node.js) for Ruby on Rails? I just need some starting points.

I already wrote a quick implementation of the client side protocol in Python. In fact the complete protocol is made up by me (the server is written in JavaScript), so I could change the protocol completely. However, the asynchronous nature cannot be changed because of the nature of the problem.

Also I need XHR polling/WebSockets in order to push the async changes to the browser. Is there a gem/howto/tutorial for that? I can't just set the request to sleep (resources!).

In case you want to know more about the background: The Rails application is a accessibility tool. The service with which it communicates is actually a Firefox Add-on that loads and renders webpages. The asynchronous nature comes from (i)frames, popup windows (window.open(), window.alert(), ...), dynamic changes to the DOM tree that have to be communicated to the Rails app, redirects (like after posing in a forum) etc. I need to use JRuby because I need to use the Jena (Java) framework for RDF processing.

A: 

Ruby On Rails is an asynchronous framework too. with a thin server. Node.js or Twisted are not a Asynchrone framework. There just Event framework.

In ruby the Event Framework is EventMachine and thin serveur use it. You can create some websocket with a rack::middleware and use it.

shingara