Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websockets versus GCM under Android: battery usage?

I need to maintain an open, two-way communication channel between an Android app and an external server. I know that I can use GCM for this, but for various reasons that don't pertain to Android, itself, I would like to use websockets, if at all possible.

Can anyone point me to a comparison of resource/battery usage stats when using GCM versus a java-based websockets client under Android?

Thanks in advance.

like image 986
HippopotamusMan Avatar asked Mar 25 '13 14:03

HippopotamusMan


1 Answers

Since multiple applications use GCM which uses a single socket connection to the Google cloud, making your application use GCM for notifications should not affect battery life at all since it just uses an existing connection. On the other hand, what ever process you create using websockets, that battery usage will just be added on top of GCM.

Also, if you need to maintain your connection even when the application is not in the foreground it will be necessary to create your application as a foreground service. GCM handles this for you.

Update
A device that has no other applications using GCM is a very rare case since many essential applications like gmail use GCM. I do not have exact numbers of the battery usage of GCM. But the battery usage of C2DM (GCM's predecessor which uses the same underlying communication model) is mentioned in this video around 4 minutes in. I actually had a similar question about the battery usage of a persistent socket connection to an external server (Android persistent socket connection rules). Although it is not a websocket I would image the battery usage to be similar. But again since GCM is built in at a much lower level of the OS, I would image it to be more optimized than a custom solution.

Unless you have some company policy against using a third party server or some very specific specifications, I would recommend using GCM. I would also encourage watching the entire video about C2DM as well as this video for GCM.

like image 58
Alex Avatar answered Sep 27 '22 22:09

Alex