19

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.

HippopotamusMan
  • 191
  • 1
  • 1
  • 4
  • You should probably choose the answer below as the correct one. – npgall May 20 '13 at 14:23
  • @HippopotamusMan I have the same request, for the same reason. Can you jump into this again? Are you still using custom WebSockets or do you use FCM / GCM? We are testing our APP and it is using a lot of battery. Not sure if this are for the WebSockets but we think so. – Michael Burger Sep 15 '17 at 14:00

1 Answers1

28

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.

Community
  • 1
  • 1
Alex
  • 2,033
  • 1
  • 24
  • 40
  • Thanks, Alex. So what about the following simple case: one and only one android process needs two-way communication with an external server? Are GCM and websockets equally efficient regarding android resource usage (battery, etc.) in this degenerate case, or would one be better than the other. – HippopotamusMan Mar 26 '13 at 11:55
  • Added an update to the answer. Couldn't fit it within the comments section. – Alex Mar 26 '13 at 15:18
  • Thanks. I'll check the video later, and your info is quite helpful. Looks like I'll probably use GCM. – HippopotamusMan Mar 26 '13 at 17:55
  • What major companies use GCM. I have read many threads citing how it can take 15min+ to send a message... – Sauron Dec 10 '14 at 03:00