GCM vs. Socket in android

后端 未结 1 1392
夕颜
夕颜 2020-12-28 17:43

In my knowledge, most of android tutorials and examples out there rely on use of GCM for sending data from server to android device; and use php scripts along with post/get

相关标签:
1条回答
  • 2020-12-28 18:18

    GCM uses sockets too. However, they are managed by the system and thus can do things a regular app cannot do. Generally, for any type of 'push' notifications, the system needs to have a long-lived socket, and a 'notification' is just some data received on that socket. All of this is not too hard to implement on an always connected machine, such as a desktop or a server, but there are additional challenges on mobile. For example, switching networks (3G<->WiFi), going out of range, maintaining a connection without keeping the device awake all the time (and killing the battery in the process). So yes, you could implement something similar using a service , sockets and your own server, but it's not trivial on mobile.

    Check out http://mqtt.org/ for an open-source implementation.

    0 讨论(0)
提交回复
热议问题