Android 上的长期持久 TCP 连接

发布于 2024-08-12 02:22:34 字数 133 浏览 2 评论 0原文

我读过网上的一些文章和 StackOverFlow 上的一些问题,但似乎没有人对 a) 如果 google 对 Gmail、邮件等使用长寿命 TCP 连接,以及 b) 如果在自定义应用程序中使用它有明确的答案会耗尽电池寿命,如果会的话,大约会消耗多少?

I've read some articles on the web and some questions on StackOverFlow, but no one seems to have a definite answer over a) If google uses Long Lived TCP connections for Gmail, Mail etc, and b) If using it in a custom app will drain battery life , and if so roughly how much?

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

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

发布评论

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

评论(3

以可爱出名 2024-08-19 02:22:34

第一个问题的答案是,是的,Google 的 GTalkService 在安装了 Google 应用程序的 Android 手机上与 Google 服务器保持持久的 XMPP 连接。

至于你的第二个问题,答案比这里的一些评论让你相信的要复杂。特别是,额外连接的保活数据包(或任何小型但持续发生的数据传输)可能会影响 3G 无线电的电源管理状态周期,这会对电池寿命产生显着影响。

有关详细信息,请参阅本文:

https://www. ericsson.com/research-blog/smartphone-traffic-impact-battery-networks/

如果可能,您可以考虑使用新的云到设备消息传送 API,它搭载在 GTalkService 之上,允许您的应用程序无需接收通知即可接收通知。维护自己的 TCP 连接。不幸的是,缺点是 C2DM 无法在纯开源 Android 上运行,它需要用户登录他或她的 Google 帐户,并且只能在 Froyo 或更高版本上使用。

The answer to your first question is that, yes, Google's GTalkService maintains a persistent XMPP connection to Google servers, on Android phones with the Google applications installed.

As for your second question, the answer to that is more complicated than some of the comments here would have you believe. In particular, additional connections' keepalive packets -- or any small but continually occurring data transfers -- can affect your 3G radio's power management state cycle, which will have a noticeable impact on battery life.

See this article for more information:

https://www.ericsson.com/research-blog/smartphone-traffic-impact-battery-networks/

If possible, you might consider using the new Cloud to Device Messaging API which piggybacks on top of GTalkService, allowing your application to receive notifications without maintaining its own TCP connection. The downsides, unfortunately, are that C2DM won't work on pure open source Android, it requires the user to be signed into his or her Google account, and it's only available on Froyo or above.

幼儿园老大 2024-08-19 02:22:34

保持开放连接可以转化为更少的资源使用:少量的“涓流”流量可以保持连接开放。

考虑相反的情况:客户端定期“轮询”服务器(假设与长期连接“涓流”相同的“刷新”率):每次打开新连接时都会产生更多流量。

连接设置/拆除的成本很高(当然,在这个宇宙中,一切都是相对的;-)。


维持开放连接的主要缺点:

  • 客户端浏览器可能会限制每个窗口/选项卡等的连接数量。
  • 中间设备(例如 NAT、防火墙)无法经常重用端口来服务其他请求

Maintaining an open-connection can translate to less resource usage: a small "trickle" traffic can maintain the connection open.

Consider the opposite situation: the Client "polls" the server on a regular interval (assume the same "refresh" rate as for the long-lived connection "trickle") : each time a new connection is opened generates more traffic.

Connection setup/teardown is expensive (of course, everything is relative in this universe ;-).


Major drawbacks of maintaining an open connection:

  • the client side browser might be limited in the number of connections per window/tab etc.
  • intermediate devices (e.g. NAT, Firewalls) can't reuse the port as often to serve other requests
九命猫 2024-08-19 02:22:34
  1. 您可以在路由器或其他计算机上使用 tcpdumpwireshark 等工具来确定 Google 应用程序保持 TCP 连接打开的时间。您需要过滤您感兴趣的端口或地址。
  2. 如果您使用 Android 1.6,确定电量消耗的最佳方法是使用新的电池使用指示器。只需安装您的自定义应用程序,然后查看显示器随时间的变化情况即可。
  1. You can use a tool like tcpdump or wireshark on your router or other machine to determine how long the TCP connections are kept open by Google's applications. You will need to filter on the ports or addresses you are interested in.
  2. If you are using Android 1.6, the best way to determine the drain is to use the new battery usage indicator. Just install your custom app and see what the monitor says over time.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文