Protocol used for sending push notification in Android

12,853

Solution 1

The protocols of the communication between the 3rd party server and GCM server (HTTP or XMPP) were already mentioned in the other answers.

The protocol of the communication between the device and GCM server is not discussed in the GCM documentation, since you never have to access it directly as an Android application developer, and therefore you don't need to know about it.

However, here's a quote from a Google developer from the team that created GCM, which says a few things about the connection. From what he says, you can only know that it's a long-lived TCP connection.

GCM maintains a long-lived connection - and reconnects if it knows the connection was broken. A router/AP/NAT is supposed to send a FIN or RST to terminate the TCP connection - so GCM and servers will know the connection is dead.

However a number of routers and mobile operators don't do this, and then GCM needs to rely on the heartbeat, ~15 min on Wifi, more on mobile.

(The quote is taken from an answer by that person)

Solution 2

There are two protocols http and xmpp which you can use to send message to GCM server.

Now its up to you what you want to use. If you want to broadcast message then u should go with http.

you can broadcast 1000 message in a single http request. And only one message through xmpp in a request...

Http can be used only for down streaming(3rd party app server -gcm-mob device)

But gcm won't support up streaming using http. for that you should use xmpp.Xmpp can be used for both up streamlining and down streaming.

Implementaction of push notification can be very easy if you are going with http and that much more hard if you are going with xmpp.but Google has provided detail tutorial how to implement xmpp. So please have a look On Google developer site.

Solution 3

Looking at @user3523641's answer and further conversation, I'll try to explain further:

The way of delivering messages is based on the protocol that you've chosen, either HTTP or XMPP (i.e., it's the same). The magic and basic way of working is leaving a socket opened between the GCM server and the user's device.

This way, when an user should receive a message, this opened socket will be used and send the message through itself. This also helps the GCM server knowing which devices are connected or not. So this way, if your third party server says a message should be sent to a user and the GCM server knows the user is not connected, it won't send it at that time, but will try once the connection is again established, so it won't waste connection attempts in vain. The default timeout is 4 weeks, however, it can be changed.

As per the official GCM documentation:

If the device is not connected to GCM, the message will be stored until a connection is established (again respecting the collapse key rules). When a connection is established, GCM will deliver all pending messages to the device, regardless of the delay_while_idle flag. If the device never gets connected again (for instance, if it was factory reset), the message will eventually time out and be discarded from GCM storage. The default timeout is 4 weeks, unless the time_to_live flag is set.

Finally, when GCM attempts to deliver a message to the device and the application was uninstalled, GCM will discard that message right away and invalidate the registration ID. Future attempts to send a message to that device will get a NotRegistered error. See How Unregistration Works for more information.

You can find more info here.

Solution 4

It uses both HTTP and XMPP

When the message is processed successfully, the HTTP response has a 200 status and the body contains more information about the status of the message (including possible errors). When the request is rejected, the HTTP response contains a non-200 status code (such as 400, 401, or 503).

iOS however, requires a dedicated TCP connection on a proprietary port, and GAE environment doesn't allow any external protocol except HTTP over port 80.

enter image description here

The message size limit is 1024 bytes. Google limits the number of messages a sender sends in aggregate, and the number of messages a sender sends to a specific device

enter image description here

This is how these components interact:

Google-provided GCM Connection Servers take messages from a 3rd-party application server and send these messages to a GCM-enabled Android application (the "client app") running on a device. Currently Google provides connection servers for HTTP and XMPP. The 3rd-Party Application Server is a component that you implement to work with your chosen GCM connection server(s). App servers send messages to a GCM connection server; the connection server enqueues and stores the message, and then sends it to the device when the device is online. For more information, see Implementing GCM Server. The Client App is a GCM-enabled Android application running on a device. To receive GCM messages, this app must register with GCM and get a registration ID. If you are using the XMPP (CCS) connection server, the client app can send "upstream" messages back to the connection server. For more information on how to implement the client app, see Implementing GCM Client.

Check out this for more details -->

Google Cloud Messaging for Android (GCM)

Android Cloud to Device Messaging Framework

Cloud Messaging

Cloud to Device Messaging

Share:
12,853
Mohammad Ashfaq
Author by

Mohammad Ashfaq

I am hybrid application developer with IBM MobileFirst platform formerly known as IBM Worklight having interest in learning new technologies. I like to solve the problems and I know couple of languages like C, C++, Java, SQL, VB.Net. I also have experience with IBM WebSphere Portal, IBM WCM, IBM Web Experience Factory, and IBM HTTP Server. I do have done the infrastructure setup of above mentioned production that includes Clustering, High Availability, Disaster Recovery etc. I am working with this technologies since December 2013, and want to explore more on this products.

Updated on June 03, 2022

Comments

  • Mohammad Ashfaq
    Mohammad Ashfaq almost 2 years

    I want to know which protocol is used to send push notification to android devices and which to send push notification requests to GCM.

    Whether it is HTTP, HTTPS or some thing else?

  • Mohammad Ashfaq
    Mohammad Ashfaq about 10 years
    And whats about GCM to device communication protocol?
  • Dev
    Dev about 10 years
    In push notification you don't have to worry about the gcm to Client(android device) [downstream ]protocol gcm itself does this task for you. But if you are Doing up streaming than only xmpp protocol will used in process
  • Mohammad Ashfaq
    Mohammad Ashfaq about 10 years
    I know that GCM will does it for me, but what if my client ask me.
  • Dev
    Dev about 10 years
    Ok if that is the case then u need to search on Google...sorry but I don't know using which protocol gcm connect to android device...
  • Mohammad Ashfaq
    Mohammad Ashfaq about 10 years
    What you have written in answer is given in android GCM documentation.
  • Dev
    Dev about 10 years
    yes, it is given in the android documentation on google's android developer site.
  • Dev
    Dev about 10 years
    visit this link it will clear all your doubt stackoverflow.com/questions/21581455/…
  • Dev
    Dev about 10 years
    or visit DEVELOPER link for official documentation link :developer.android.com/google/gcm/server.html
  • Kanagavelu Sugumar
    Kanagavelu Sugumar about 5 years
    Is there any advantage of long-lived TCP over websocket?