开发者

How to asynchronously receive data into a Rails app from an iPhone app?

A large part of a project I'm working on now deals with sending certain messages, which can easily and preferably be XML, from an iPhone app to a Ruby On Rails app. The webapp will have to instantly 开发者_运维知识库show these messages, so reloading the page isn't really an option.

I've been unable to find any info re: creating this sort of listening process for a POST request, can anyone guide me in the right path, and perhaps shed some light on what I should be doing, if I am overlooking something?

edit: Would using sockets be smarter? The apps will be run from iPod Touches/iPads in the same wifi network.

Thanks!


What you're trying to accomplish is doable, but certainly not one of the strengths of Ruby on Rails. If you need to update messages in the browser in realtime you can use JSSockets. But you need a server backend that is able to deal with lots of persistent connections like nodejs or if you prefer to use ruby EventMachine. If you still want to receive the messages via your rails app, the flow of data would be

  1. Rails app receives the Message (say by POSTing XML to /messages)
  2. The rails app posts the message into a message queue. Have look at resque
  3. The Evented server listens to the queue and posts messages to the browser

Update: Sorry, I misread your question as the iPhone app being only the sending part. Unfortunately you can't use JSSockets on the iPhone as it comes with an Adobe Flash component for communication. However, you still have the option of using long polling or implementing the socket in Objective-C and pushing the received objects into your webview via [webview stringByEvaluatingJavascriptString].

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜