views:

51

answers:

1

Hello everyone,

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!

+1  A: 

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].

flitzwald
I'm not entirely hell-bent on using Rails, It's just my preferred strategy. Node.js actually looks like it might be what I need, do you have any advice for integrating it into a rails app? The rest of the app is database driven, so I can't quite ditch something like Rails altogether
danny z
Unfortunately I'm not aware of any way to integrate an evented framework as part of a rails application (plug in style). The paradigms are just totally different. The way of integration would be message passing via a message queue. And it's quite simple too.
flitzwald
I actually think I mis-worded it, or you twice misread. I wanted the Iphone to only send, the webapp would have to both send a message, a confirmation of receipt and receive messages as well
danny z