简体   繁体   English

如何从iPhone应用程序异步接收数据到Rails应用程序中?

[英]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. 我正在处理的项目的很大一部分现在都在处理从iPhone应用程序到Ruby On Rails应用程序发送某些消息的过程,这些消息可以轻松地(最好是XML)发送。 The webapp will have to instantly show these messages, so reloading the page isn't really an option. Webapp必须立即显示这些消息,因此重新加载页面并不是真正的选择。

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? 我一直找不到任何信息:为POST请求创建这种侦听过程,有人可以引导我走正确的路,如果我忽略了某些内容,也许可以阐明我应该做的事情?

edit: Would using sockets be smarter? 编辑:使用套接字会更聪明吗? The apps will be run from iPod Touches/iPads in the same wifi network. 这些应用程序将从同一WiFi网络中的iPod Touch / iPad运行。

Thanks! 谢谢!

What you're trying to accomplish is doable, but certainly not one of the strengths of Ruby on Rails. 您试图实现的目标是可行的,但肯定不是Ruby on Rails的优势之一。 If you need to update messages in the browser in realtime you can use JSSockets . 如果您需要在浏览器中实时更新消息,则可以使用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 . 但是,您需要一个能够处理许多持久性连接(例如, nodejs)或者如果您更喜欢使用ruby EventMachine的服务器后端。 If you still want to receive the messages via your rails app, the flow of data would be 如果您仍然想通过Rails应用接收消息,则数据流将是

  1. Rails app receives the Message (say by POSTing XML to /messages ) Rails应用接收消息(例如,通过将XML发布到/messages
  2. The rails app posts the message into a message queue. Rails应用程序将消息发布到消息队列中。 Have look at resque 看一下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. 更新:对不起,我误解了您的问题,因为iPhone应用程序只是发送部分。 Unfortunately you can't use JSSockets on the iPhone as it comes with an Adobe Flash component for communication. 不幸的是,您无法在iPhone上使用JSSockets,因为它带有Adobe Flash组件用于通信。 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] . 但是,您仍然可以选择使用长时间轮询或在Objective-C中实现套接字,并通过[webview stringByEvaluatingJavascriptString]将接收到的对象推入[webview stringByEvaluatingJavascriptString]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM