本文介绍了基于TCP的RPC服务器(二郎或类似的东西?)的iOS / Android应用程序通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建在iOS和Android原生移动应用程序。这些应用程序需要往返于服务器实时更新,与任何其他基于网络的应用程序执行(脸谱,微博,社交游戏类的字眼与朋友等)

I'm building native mobile applications in both iOS and Android. These apps require "realtime" updates from and to the server, same as any other network-based application does (Facebook, Twitter, social games like Words with Friends, etc)

我想使用HTTP长轮询,这是超必杀的,即长轮询可能会损害电池寿命,尤其是大量的TCP建立/拆除的。它可能是有意义的有移动应用程序使用持久TCP套接字建立到服务器的连接,并发送RPC样式的命令到服务器为所有Web服务的通信。这ofcourse,需要一台服务器来处理长期存在的TCP连接,并能讲一个Web服务,一旦它使传下来的TCP管道的数据的意义。我想使用JSON或XML传递数据以纯文本的。

I think using HTTP long polling for this is over kill in the sense that long polling can be detrimental to battery life, especially with a lot of TCP setup/teardown. It might make sense to have the mobile applications use persistent TCP sockets to establish a connection to the server, and send RPC style commands to the server for all web service communication. This ofcourse, would require a server to handle the long-lived TCP connection and be able to speak to a web service once it makes sense of the data passed down the TCP pipe. I'm thinking of passing data in plain text using JSON or XML.

也许一个Erlang基于RPC服务器将做好的基于网络的应用程序是这样的。这将允许移动应用从服务器发送和接收数据全不带多设置/一个连接拆除,个别的HTTP请求使用类似NSURLConnection的iOS上会怎么做。因为没有网络浏览器是不参与,我们并不需要处理的HTTP在移动客户端级别的细微差别。很多这些彗星和长轮询/流媒体服务器是建立与HTTP的初衷。我想只使用纯文本协议在TCP足够好,就会使客户端更敏感,允许从服务器接收更新和preserve电池寿命比传统的长轮询和流模型。

Perhaps an Erlang based RPC server would do well for a network based application like this. It would allow for the mobile apps to send and receive data from the server all over one connection without multiple setup/teardown that individual HTTP requests would do using something like NSURLConnection on iOS. Since no web browser isn't involved, we don't need to deal with the nuances of HTTP at the mobile client level. A lot of these "COMET" and long-polling/streaming servers are built with HTTP in mind. I'm thinking just using a plain-text protocol over TCP is good enough, will make the client more responsive, allow for receiving of updates from the server, and preserve battery life over the traditional long polling and streaming models.

有谁目前做到这一点与他们的原生iOS和Android应用程序?你写你自己的服务器或者是有什么开源。在那里,我可以开始今天的工作,而不是重新发明轮子?有没有为什么只使用基于TCP的RPC服务有任何理由比使用一个更坏的决定HTTP?

Does anyone currently do this with their native iOS or Android app? Did you write your own server or is there something open sourced out there that I can begin working with today instead of reinventing the wheel? Is there any reason why using just a TCP based RPC service is a worse decision than using HTTP?

我也看了成HTTP管线,但它不看是值得的麻烦,当它涉及到在客户端上实现它。此外,我不知道这是否会允许在客户端和LT双向通信; - >服务器通信通道

I also looked into HTTP pipelining, but it doesn't look to be worth the trouble when it comes to implementing it on the clients. Also, I'm not sure if it would allow for bi-directional communication in the client<->server communication channel.

任何有识之士将大大AP preciated。

Any insight would be greatly appreciated.

推荐答案

使用TCP套接字与自己的协议滚落比HTTP相当好尤其是资源在移动设备上的性质。二郎神会做的相当不错,但是让从协议开始。二郎神也擅长此特别是在 位语法 EX pressions。不过是,你可以,你想使用纯文本。 JSON(需要一个解析器: Mochijson2.erl 中发现的 受Mochiweb库 )和XML(需要一个解析器: Erlsom

Using TCP sockets with your own protocol rolled down is quite better than HTTP especially with the nature of resources on the mobile devices. Erlang will do quite well, however lets start from your protocol. Erlang excels well at this especially with the Bit Syntax expressions. However still, you could use plain text as you wish. JSON (would need a parser: Mochijson2.erl found in Mochiweb library) and XML (will need a parser: Erlsom).

我亲自制作中,我们使用原始TCP套接字与我们二郎服务器和移动设备的项目。但是,根据您选择的端口号,沿途路由器将封锁取决于服务提供商的安全策略/丢弃数据包。不过,我仍然认为,HTTP可以工作。人们聊天的Facebook手机,从他们的设备发送蠢特夫妇等,并深信这些社交引擎使用某种长轮询或服务器推送或什么,但使用HTTP的。移动设备拥有先进的后期能力。

I have personally worked on a project in which we were using raw TCP Sockets with our Erlang Servers and Mobile Devices. However, depending on the Port numbers you choose, Routers along the way would block/Drop packets depending on the security policies of service providers. However, i still think that HTTP can work. People chat on Facebook Mobile, send Twits e.t.c from their devices and am sure these social engines use some kind of Long Polling or Server Push or whatever but using HTTP. The mobile devices have advanced in capability of late.

滚动自己的基于TCP协议附带了许多挑战:端口选择,无论是在客户端和服务器,安全问题等数据解析使用HTTP会让你觉得比花时间修正协议的问题,在客户端或服务器的实际问题。您在上面像Android和iOS(的iPad,iPhone等)所提到的设备是非常有能力处理HTTP COMET(长轮询)。我相信,当您按照在 标准,在移动设备上的Web应用程序 以及这些的 W3C移动Web最佳实践 ,您的应用程序将运作良好使用HTTP。

Rolling your own TCP Based protocol comes with a number of challenges: Port selection, Parsing of data both at the client and server, Security issues e.t.c. Using HTTP will let you think of the actual problem than spending time correcting protocol issues at client or server. The Devices you've mentioned above like Android and IOS (Ipad, Iphone e.t.c) are very capable of handling HTTP COMET (Long polling). Am sure when you follow the standards for Web Applications on Mobile devices as well as these W3C Mobile Web Best Practices, your app will function well using HTTP.

使用HTTP方法将加快工作,也有很多在这些设备上这将帮助您原型你想比滚动自己的基于TCP的明文协议情况的解决方案的软件开发工具包库。要备份这个道理,通过这些看的 W3C发现

Using HTTP methods will quicken the work and there are a lot of libraries on the SDKs of these Devices which would assist you prototype the solution you want as compared to the situation of rolling your own TCP-based plain text protocol. To back up this reasoning, look through these W3C findings.

让我最后说的这些设备上的HTTP好处。如果您是使用Web技术用于移动设备,如 的Opera Widget 电话峡 jQuery Mobile的 ,他们的软件开发工具包和库具有优化已经替您完成或已经有据可查的,你的应用程序可以进行有效的方法。再者,这些技术有API访问本机设备资源,如电池检查,短信,彩信,GSM广播频道,联系人,照明,GPS和记忆;一切如JavaScript类的API。它会变硬(不灵活)如果你使用像本地编程语言的 J2ME 移动的Python 相比,使用Web技术,比如上面提到的CSS3,HTML5和JavaScript工具。使用上面提到的网页制作工具会使您的应用程序很容易被发言权分配的 Ovi商店 苹果店 ,从经验。

Let me finally talk of the HTTP benefits on these Devices. If you are to use Web technologies for Mobile devices, such as Opera Widgets, Phone Gap, Sencha Touch, and JQuery Mobile, their SDKs and Libraries have Optimizations already done for you or have well documented ways in which your app can be made efficient. Further still, these technologies have the APIs to access the native Devices' resources like Battery check, SMS, MMS, GSM broadcast channels, Contacts, Lighting, GPS , and Memory; all as APIs in the JavaScript classes. It would become hard (inflexible) if you use native programming languages like J2ME, Mobile Python or Symbian C++ / Qt as compared to using Web technologies like CSS3, HTML5 and JavaScript tools mentioned above. Using the Web tools mentioned above will make your app easily distributable by say Ovi Store or Apple Store, from experience.

必须注意,如果你使用HTTP,测试将很容易。所有你需要的是一个公共领域,以便在移动设备上的小工具在互联网上找到你的服务器。如果你角色你自己的TCP / IP协议,网络路由器可能是破坏性的打击,你使用,除非你打算使用端口80或另一个众所周知的端口的端口号,但​​后来还是你的服务器的IP都必须公开。有一个捷径:如果你把你的TCP服务器相同的ISP为您的测试手机的互联网连接的背后,ISP的路由器会看到源和目标作为其网络的后面。但所有的一切,也有与滚动自己的协议的挑战。

Take note that if you use HTTP, testing will be easy. All you need is a public Domain so the Widgets on the mobile device locates your servers over the Internet. If you role your own TCP/IP protocol, the Network Routers may be disruptive against the Port number you use unless you plan on using port 80 or another well known port, but then still your Server IP would have to be made Public. There is a short cut to this: if you put your TCP Server behind the same ISP as your testing Mobile's Internet connection, the ISP routers will see both source and destination as behind its Network. But all in all, there are challenges with rolling your own protocol.

编辑:使用HTTP,你会从 受益的 REST。 // github上:在二郎(尤其是 雅司病 )擅长REST服务。看看这篇文章:与雅司病 RESTful服务 。对于受Mochiweb,有一个有趣的文章有关: 一个百万用户彗星应用程序使用受Mochiweb 被分为3个部分。再者,你可以看看在 solution对此问题

Using HTTP, you will benefit from REST. Web Servers implemented in Erlang (especially Yaws and Mochiweb) excel at REST services. Look at this article: RESTFUL services with Yaws. For mochiweb, there is an interesting article about: A million User comet application using Mochiweb which is broken into 3 parts. Further still, you could look at the solution given to this question.

这篇关于基于TCP的RPC服务器(二郎或类似的东西?)的iOS / Android应用程序通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:06