开发者

rails asynchronous communication and xhr polling

开发者 https://www.devze.com 2023-01-21 04:06 出处:网络
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 n

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.


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.


Have a look at Juggernaut 2, it does exactly this (and it also uses node). I am using it to push messages from my server to all connected clients and it works great. Implementation was a breeze (although the readme is a bit unclear on certain things), lemme know if you need any help with it.

0

精彩评论

暂无评论...
验证码 换一张
取 消