推荐替代webkit,用于iOS上的服务器发送事件 [英] Recommended alternative to webkit for server-sent events on iOS

查看:95
本文介绍了推荐替代webkit,用于iOS上的服务器发送事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的原生iOS应用中接收服务器发送事件,但是我没有使用webkit / Safari。根据我的发现,NSURLConnection很不适合 chunk响应。我还看了 ZTWebSocket 库(显然不错,但我正在寻求SSE,而不是网络插座。 CocoaAsyncSocket 是否合适?还是仅限于纯TCP Socket通信?



我有一种潜在的怀疑,我错过了一些明显的东西,或者已经有了一个库或样本。在此先感谢。

解决方案

经过对此的更多研究后,我认为在iOS上实施Server Sent Events的最佳方式没有WebKit就是使用自定义的NSConnection / NSRequest工具集。我选择了 ASIHTTPRequest 。此库允许您显式控制连接对象上的持久性属性(必要),控制通过流接收的数据,存储响应(例如,在本地文件中)等。



更不用说它在网络领域包含许多其他方便的扩展/自定义(改进的Reachability观察器,异步的简化API,排队功能,甚至加载整个网页的能力(CSS,js和所有)。 / p>

在服务器端,我使用的是cyclone-sse(龙卷风)和nginx(作为反向代理)。非常令人兴奋,现在我可以看到我的SSE同时被推送到我的iOS模拟器和浏览器订阅者.Cyclone甚至处理所有连接,并为我提供了一个支持简单POST消息推送的API(也支持AMQP和Redit)......



长话短说,ASIHTTPRequest对我来说是一个完美的解决方案。


I would like to receive Server-Sent Events in my native iOS app however am not using webkit/Safari. From what I've found, NSURLConnection is poor fit as it chunks response . I've also looked at ZTWebSocket library (obviously nice, but I'm seeking SSE, not web sockets). Would CocoaAsyncSocket be appropriate? Or limited to pure TCP Socket communication?

I have a sneaking suspicion that I am missing something obvious, or there'd be a library or sample for this already. Thanks in advance.

解决方案

After some more research on this, it's my opinion that the best way to implement Server Sent Events on iOS without WebKit is to use a customized NSConnection/NSRequest toolset. I settled on ASIHTTPRequest . This library allows you to explicitly control persistence attribute on connection object (essential), control data as it is received over the stream, store responses (e.g. in local files), etc.

Not to mention it contains lots of other handy extensions/customizations in the realm of networking (improved Reachability observer, a simplified API for async, a queuing feature, even ability to load entire web pages (CSS, js and all).

On the server side, I'm using cyclone-sse (tornado) and nginx (as a reverse proxy). Pretty exciting, now I can see my SSEs pushed simulataneously to both my iOS simulator and a browser subscriber. Cyclone even handles all the connections and gives me an API which supports simple POST for message pushes (also supports AMQP and Redit)...

Long story short, ASIHTTPRequest was a perfect solution for me.

这篇关于推荐替代webkit,用于iOS上的服务器发送事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆