用于实现实时聊天应用程序的推送通知与 Web 套接字? [英] Push Notification vs. Web Sockets for implementing a real-time chat app?

查看:30
本文介绍了用于实现实时聊天应用程序的推送通知与 Web 套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑为 iPhone 构建一个实时聊天应用程序(但这个问题也适用于 Android 和其他设备)基本上我希望应用程序在打开和关闭时接收实时消息,只是就像 iPhone 自带的消息"应用一样.

I'm looking into building a real-time chat app for iPhone (but this question applies to Android and other devices as well) Basically I want the app to receive realtime messages while it's open as well as while it's closed, just like the iPhone's own "Message" app.

当它关闭时,我可以使用像 APNS 这样的原生推送通知服务,当应用程序打开时,我可以运行我自己的 websockets 服务器或使用像 PubNub 或 Pusher 这样的 3rd 方提供商,这就是我一直在做的.

When it's closed I can use the native push notification services like APNS, and when the app is open, I can run my own websockets server or use 3rd party providers like PubNub or Pusher, which is what I've been doing actually.

然后我想知道:为什么我不能在应用程序打开和关闭时完全依赖 APNS 进行实时消息传递?这感觉像是一个更简洁的解决方案,因为它由一个推送服务器驱动.有人可以启发我吗?谢谢.

Then I wondered: Why can't I completely rely on APNS for the real-time messaging, both while the app is open and while it's closed? This feels like a much cleaner solution since it's driven by one push server. Could someone enlighten me? Thanks.

推荐答案

APNS 并非 100% 可靠.在大多数情况下是这样,但不是 100%.它也不如您提供的专门服务那么快.有时,推送消息需要一分钟以上才能到达.您需要考虑这些,并在您提出的任何设计中加以考虑.如果您能忍受这些限制,您确实可以依靠 APNS 来更新您的客户端.此外,借助 iOS7,应用可以在后台唤醒、检索数据并更新其 UI,以便向用户展示最新的应用.

APNS is not 100% reliable. It is in most cases, but not 100%. It is also not as quick as a dedicated service you would offer. Sometimes, push messages take upwards of one minute to arrive. You need to consider these and take it into consideration in any design you come up with. If you can live with these limitations, you can indeed rely on the APNS to update your client. Moreover, with iOS7, an app could wake up in the background, retrieve data and update its UI so that user is presented with an up-to-date app.

在谈到性能时,能够处理大量打开的连接并同时为它们提供服务并不像听起来那么简单,因此根据您的资源,您可能无法提供比 Apple 的 APNS 更好的服务正常运行时间,因此上述限制虽然属实,但并不一定像听起来那么糟糕.

While speaking about performance, to be able to handle a multitude of open connections and service them concurrently is not as simple as it sounds, so depending on your resources, you may not be able to provide a better service uptime than Apple's APNS, so the limitations above, while true, are not necessarily as bad as they may sound.

我认为最好的办法是,因为无论如何您都需要实施推送支持,只实施 APNS,看看这是否满足您和您的客户的需求.请记住,沙箱(调试)APNS 服务器比正常的生产 APNS 服务器慢,因此请使用发布版本进行测试,以了解仅使用 APNS 的实际性能影响.如果您发现所提供的服务不够用,您只能实施进一步的服务.

I think best would be, since you need to implement push support anyway, to implement APNS only, and see if this satisfies you and your clients. Remember that the sandbox (debug) APNS servers are slower than normal production APNS servers, so test with release versions to see the real performance implications of going APNS-only. If down the road you notice that the provided service is not enough, you can only implement further services.

这篇关于用于实现实时聊天应用程序的推送通知与 Web 套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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