Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long Lived Persistent TCP Connection on the Android

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?

like image 679
Faisal Abid Avatar asked Nov 18 '09 15:11

Faisal Abid


3 Answers

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.

like image 180
mshroyer Avatar answered Oct 28 '22 07:10

mshroyer


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
like image 27
jldupont Avatar answered Oct 28 '22 07:10

jldupont


  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.
like image 1
Adam Goode Avatar answered Oct 28 '22 07:10

Adam Goode