How does persistent tcp/ip connections preserve battery and lower bandwidth usage?

狂风中的少年 提交于 2019-12-03 17:08:05

The way that it preserves battery life and bandwidth usage is a little indirect. The savings come in the form of having one service maintaining a persistent connection rather than every application on your device continually creating/destroying connections and continually using bandwidth.

For instance, if you have Facebook, Instagram, and Twitter apps on your phone, in order to keep everything up to date, you would have three apps polling servers continually for changes.

The solution is to have one service listening for incoming connections and having that service notify the individual application that there are updates.

Inti Gonzalez-Herrera

First you must have into account the state machine implemented by devices to control the power consumption due to network communication. You can see it here After reading that you will see that, as Adam said, creating connections is very bad for you battery-life and polling is about creating/destroying connections.

Therefore, C2DM avoids creating connections to improve power consumption. In the end, the saving is due to:

  1. A persistent connection doesn't mean that the device is always in full-power state. It only means that the connection is not closed and then the server can send messages to the client.
  2. C2DM delivers messages with different mechanisms as you can read in GCM Advanced Topics. Hence, it can be configured to deliver messages only when the devices is already in full-power state
  3. The last factor is how GCM delivers messages to idle devices. It is quite unclear in the official documentation and I think that the source code for Google Play Service is not available. Nonetheless, you can get some clues with the following answer here. The first commentary seems useful.

There is a point I am not sure: I don't know how they keep the connection alive at low-level. That's the piece I am missing. You can read Android C2DM slide 15 for some explanation. It seems that they provide some kind of clever handling of the state machine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!