English 中文(简体)
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?

最佳回答

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.

问题回答

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
  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.




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签