title: rails asynchronous communication and xhr polling
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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!).</p>
  
  <p>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 (<code>window.open()</code>, <code>window.alert()</code>, ...), 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.</p>