iPhone 上的 COMET(服务器推送到客户端)

发布于 2024-07-09 10:17:17 字数 1453 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

她说她爱他 2024-07-16 10:17:17

有多种解决方案可用于使用 STOMP 客户端。

STOMP 非常简单且轻巧,非常适合 iPhone。

我使用这个作为我的起点,发现它非常好。 它有一些对象分配/内存泄漏问题,但是一旦我掌握了 iPhone 编程的窍门,这些问题就很容易解决。

希望有帮助!

There are a couple of solutions available to use a STOMP client.

STOMP is incredibly simple and lightweight, perfect for the iPhone.

I used this one as my starting point, and found it very good. It has a few object allocation/memory leak problems, but once I got the hang of iPhone programming, these were easy to iron out.

Hope that helps!

旧城空念 2024-07-16 10:17:17

您可以在您的应用程序中使用普通的 TCP/IP 套接字吗?

A) 如果是,那么原始 TCP/IP 套接字绝对是更优雅的解决方案。 从您的 iPhone 应用程序中,您只需等待通知事件。 只要您的应用程序打开,套接字就打开。 如果您愿意,您甚至可以使用 HTTP 协议/标头。

在服务器端,您可以使用一些框架来编写服务器,以有效地处理数千个打开的 TCP/IP 连接。 例如 TwistedEventMachinelibevent。 然后只需将服务器主套接字绑定到 http 端口 (80)。

这个想法是使用一个服务器,每个客户端只保留一个数据结构。 从某些数据库应用程序接收更新事件,然后将其推送到正确的客户端。

B) 不可以,你必须在 iPhone 端使用 Apache 和 http 客户端。 那么您应该知道,整个 COMET 解决方案实际上是为了解决 HTTP 协议和 Apache / PHP 的限制。

Apache 旨在处理许多短时间连接。 据我所知,只有最新版本的 Apache (mpm worker) 才能有效地处理大量打开的连接。 以前,Apache 为每个连接保留一个进程。

Web 浏览器对一台 Web 服务器的并发打开连接有限制(实际上是 URL 地址,例如 www.foo.com,而不是 www.foo.com 的 IP 地址)。 并且限制为 2 个连接。 此外,浏览器仅允许与下载 HTML 主页面的同一服务器进行 AJAX 连接。

Can you use ordinary TCP/IP socket in your application?

A) If yes then definitely a raw TCP/IP socket is more elegant solution. From your iPhone app you just wait for notification events. The socket is open as long as your application is open. If you want you can even use HTTP protocol / headers.

On the server side you can use some framework to write servers which efficiently handle thousands of open TCP/IP connections. e.g Twisted, EventMachine or libevent. Then just bind the server main socket to http port (80).

The idea is to use a server which keeps just a single data structure per client. Receives update event from some DB application and then pushes it to right client.

B) No, you have to use Apache and http client on iPhone side. Then you should know that whole COMET solution is in fact work around for limitations of HTTP protocol and Apache / PHP.

Apache was designed to handle many short time connections. As far I know only newest versions Apache (mpm worker) can handle efficiently big number of opened connection. Previously Apache was keeping one process per connection.

Web browsers have a limit of concurrent open connections to one web server (URL address in fact, eg. www.foo.com, not IP address of www.foo.com). And the limit is 2 connections. Additionally, a browser will allow only for AJAX connections to the same server from which the main HTML page was downloaded.

无言温柔 2024-07-16 10:17:17

我写了一个网络服务器来完成这种事情。 我正在通过长轮询的服务器推送实时更新,例如,我有 iPhone 上的 safari 显示该数据。

给定的服务器实例应该能够处理几千个并发客户端,而无需太努力。 我有一个计划将它们放入层次结构中,以允许更多的水平缩放(应该非常简单,但不会影响我当前的应用程序)。

I wrote a web server for doing exactly this kind of thing. I'm pushing realtime updates through the server with long polling and, as an example, I had safari on the iPhone displaying that data.

A given instance of the server should be able to handle a few thousand concurrent clients without trying too hard. I've got a plan to put them in a hierarchy to allow for more horizontal scaling (should be quite trivial, but doesn't affect my current application).

爱已欠费 2024-07-16 10:17:17

WebSync 有一个可在 iPhone 上运行的 javascript 客户端(如果您需要的话)

WebSync has a javascript client that works on the iPhone, if that's what you're after

隔纱相望 2024-07-16 10:17:17

长轮询能达到您想要实现的目标吗? 您可以用几行常规 Javascript 来实现客户端,这比任何框架都更轻。

在 ObjC 中实现它也很简单(连接,等待响应或超时,重复)

我的问题的答案 简单的“长轮询”示例代码? 希望能解释一下长轮询是多么简单。

基本上,您只需像往常一样请求一个 URL - Web 服务器会接受连接,但不会发送任何内容数据直至可用。 当您接收数据或连接超时时,您需要重新连接(并重复)

最复杂的部分是服务器端,因为您不能使用像 Apache 这样的常规线程 Web 服务器,尽管 Comet 也是如此..

Would long-polling work for what you want to achieve? You can implement the client-side in a few lines of regular Javascript, which will be lighter than any framework could possibly be.

It would also be trivial to implement it in ObjC (connect, wait for a response or timeout, repeat)

The answers to my question Simple "Long Polling" example code? hopefully explain how extremely simple Long Polling is..

Basically you would just request a URL as usual - the web-server would accept the connection, but not send any data until it's available. When you receive data, or the connection times-out, you reconnect (and repeat)

The most complicated bit would be server server-side, as you cannot use a regular threaded web-server like Apache, although this is also the case with Comet..

池木 2024-07-16 10:17:17

StreamHub Comet Server 开箱即用,无需任何插件或任何东西。 只需在我的 iPhone 上浏览他们的网站,所有示例都有效,不需要安装 Flash 或其他任何东西。

StreamHub Comet Server works with the iPhone out of the box, no plugins or anything required. Just browsed to their website on my iPhone and all the examples worked, didn't need to install Flash or anything.

成熟稳重的好男人 2024-07-16 10:17:17

您想要/已经通过 http 为您的应用程序进行通信吗? 如果没有,您可以使用 CFNetwork 框架使用套接字(TCP/UDP)来允许您的应用程序和服务器进行通信。 从我对 CFNetwork 堆栈的了解来看,它非常酷,并且使得读取和写入流变得相当简单,并且允许同步和异步通信。 它还允许您在套接字上定义回调,以便您获得有关接收数据、建立连接等事件的通知。因此,在您的示例中,您可以通过套接字将信息发送到服务器,然后您可以定义一个回调将侦听流上的传入数据,然后相应地更新您的应用程序。

编辑:做了更多的研究,如果您采用套接字方法,您可能还想看看 NSStream 类。 它们是构建在 CFSocket 之上的 Cocoa 抽象。

Do you want/have do the communication for your app over http? If not, you can use CFNetwork framework to use sockets (TCP/UDP) to allow your app and server to communicate. From what I have seen of the CFNetwork stack, it is pretty cool, and makes it fairly straitforward to read and write to streams, and allows for synchronous and asynchronous communication. It also allows for you to define callbacks on your socket allowing you to get notified of events like data received, connection made, etc. So, in your example you could send the information over the socket to your server, and then you could define a callback that would listen for incoming data on the stream and then update your app accordingly.

EDIT: Did a little more research, and if you go the socket approach, you may want to also look at the NSStream classes. They are Cocoa abstractions build on top of the CFSocket stuff.

蝶舞 2024-07-16 10:17:17

您没有提到您正在使用什么服务器端技术。 但如果它是 microsoft .net(或任何其他遇到此问题的 googler),则有一个简单的 comet 选项: http://www.codeplex.com/ncomet

you didn't mention what serverside tech you're using. But in case it's microsoft .net (or for any other googlers who come across this), there is a simple option for comet: http://www.codeplex.com/ncomet.

三生殊途 2024-07-16 10:17:17

COMET、LightStreamer、AJAX 所有这些垃圾都被打破了。 TCP 的基础是,如果没有 ping 流量,就无法保证“保持活动”。因此,如果要保证良好的可靠性或及时交付,您可以忘记长轮询。

这只是每个人在 2003 年就看到的炒作当跛脚狂热开始时..

COMET, LightStreamer, AJAX all that junk is broken. It is basics of TCP that no 'keep-alives' are ever guaranteed without pinging traffic.. So you can forget that long-polling if any decent reliability or timely delivery is to be guaranteed..

It's just hype everyone saw through back in 2003 when the lame-mania kicked off..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文