与应用程序服务器相比,使用 C2DM 有何优势?

发布于 2024-11-26 16:30:57 字数 43 浏览 1 评论 0原文

为什么应用服务器不能直接向应用程序发送消息?中间为什么需要C2DM服务?

Why can't the application server send messages directly to the application? Why do you need the C2DM service in the middle?

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

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

发布评论

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

评论(2

﹏雨一样淡蓝的深情 2024-12-03 16:30:57

要从服务器端发送消息,您有两种可能性:

  1. 客户端以一定的时间间隔轮询新消息。 缺点:不是实时解决方案。如果您轮询太频繁,它会耗尽电池电量,消耗您的配额(如果您没有无限套餐)。通常,您会做很多不必要的工作和流量,因为大多数民意调查不会返回任何消息。
  2. 始终保持联系。 缺点:技术上很难交付,因为手机在进入睡眠模式时可能会关闭连接。 (至少没有什么可以保证他们不会)。此外,您还 24/7 运行后台应用程序。

C2DM 的当前状态将为您提供:

  1. 即使您的应用程序未运行,也能够获取消息,因为 Android 将在以下情况下启动您的应用程序(您配置的部分,不一定是整个 UI):消息到达。
  2. 传递此类消息的中央共享渠道。如果您的手机上有 10 个应用程序需要实时通知,那么这只是一个设施,而不是并行运行和轮询的 10 个应用程序。
  3. 承诺:由于这是 Google 批准的用于推送消息的 API,因此您可以期待它在未来得到优化。一项改进可以是用于启动 C2DM 会话的运营商级消息传递。这意味着你可以让手机 100% 的“智能”部分进入睡眠状态。

To send a message from the server side you have two possibilities:

  1. The client polls for new messages in certain intervals. Downside: Not a real-time solution. If you poll too frequently it will drain battery, consume your quota (if you don't have an unlimited package). Generally you do a lot of unnecessary work and traffic as most polls will return no messages.
  2. Stay connected all the time. Downside: hard to deliver technically as phones can close connections when going to sleep mode. (At least nothing guarantees that they won't). Also you are running a background application 24/7.

The current state of C2DM will give you:

  1. The ability to get messages even when your application is not running as Android will start your application (the part of it you configured, not necessarily the whole UI) when a message arrives.
  2. A central, shared channel to deliver such messages. If 10 applications need real-time notifications on your phone this is one single facility, not 10 applications running and polling in parallel.
  3. The promise: As this is the sanctioned API by Google for push messaging you can expect it to be optimized in the future. One improvement can be carrier-level messaging to initiate a C2DM session. That would mean you can put 100% of the "smart" part of your phone asleep.
╭⌒浅淡时光〆 2024-12-03 16:30:57

因为应用程序不能(或不应该)充当服务器。

如果您想直接向您的应用程序发送消息,那么您的应用程序将需要某种服务器在某个端口进行侦听。这很糟糕,因为:

  1. 连接通常是受防火墙保护的,您不能只侦听某些端口,
  2. 您的设备可能被关闭或没有连接(然后您的应用程序服务器需要重试),
  3. 应用程序服务器需要知道您设备的地址,
  4. 应用程序需要一直运行(至少是服务器模块),这对电池不友好。

Because the application can't (or isn't supposed to) act as a server.

If you would like to send messages to your app directly, then your application would need to have some sort of server listening in some port. This is bad because:

  1. connections are usually firewalled, you cant just listen in some port,
  2. your device can be turned off or without connectivity (then you app sever would need to retry),
  3. the app server would need to know the address of your device,
  4. app would need to be running (at least the server module) all the time, this isn't battery friendly.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文