Google Cloud Messaging - Messages Sometimes Not Received Until Network State Changed

Google Cloud Messaging - messages sometimes not received until network state changed

I've noticed this as well. Although I haven't dug into the actual code, here's my understanding of why this happens.

GCM (and most push messaging services) works by keeping a long-lived socket open to Google's push notification server. The socket is kept open by sending "heartbeat" messages between the phone and server.

Occasionally, the network state may change and this socket will be broken (because the IP address of the device changes, from 3g to wifi, for example). If the message comes in before the socket is reestablished, then the device will not immediately get the message.

The reconnection only happens when the phone notices the socket is broken, which only happens when it tries to send a heartbeat message.

Again, just my basic understanding of how it works and why it happens, and I could be wrong.

Google Cloud Messaging - messages either received instantly or with long delay

The GCM framework part on the client phone use a TCP connection on the port 5228. This connection its used for push notifications, but as every tcp connection it can go on timeout with some routers/carriers that apply strict policies to kill inactive tcp connections (tcp idle timeout).

Most wifi routers kills inactive connections after 5 minutes for example, like mine.

The GCM framework use a keep-alive mechanism to send an heartbeat network packet every 15 minutes on wifi and every 28 minutes on 3G. This keep-alive is not always reliable for all users.

I opened the issue to google here:
https://productforums.google.com/forum/#!category-topic/nexus/connecting-to-networks-and-devices/fslYqYrULto
They agree there is currently an issue.

EDIT (2014/01/08): currently Google updated the heartbeat intervals to 8 minutes for wifi and mobile connections. Tha'ts a remote change which impact all android devices 2.2+
This is a good improvment to avoid the tcp push connection timeout. Still, if a wifi router kill inactive connections after 5 minutes, you will have a 3 (8-5) minutes delay in push notifications (if you hadn't other notifications that keep alive the connection)

EDIT (2016/03/06): now google seems to be testing my 2 years ago feedback, to have a dynamic mechanism to determinate the right heartbeat interval depending from the network. Currently seems a staged rollout and only for wifi as for what I know. So based on the wifi SSID the algorithm determine the right heartbeat interval for the specific wifi with a sort of stepwise refinement. This sound very good! This is a remote change which impact every android phone that has Google Play Services.

GCM Push messages being kept on the server until a new one arrives

This seems like an issue of time_to_live parameter on the message payload. Quoting Android Docs on the same:

time_to_live: How long (in seconds) the message should be kept on GCM storage if the device is offline.(default time-to-live is 4 weeks).

Good Luck !

Google Cloud Messaging not working on 4.1.2 devices on a corporate network

I've finally figured out what the problem is. The corporate firewall is blocking traffic on the native GCM port of 5228. (5229 and 5230 are also mentioned with relation to GCM but we're not seeing any attempted traffic on those ports at all.) This much is well documented elsewhere (just Google GCM port 5228).

What I can't find clearly documented anywhere, but we've figured out from our server logs and from running Connection Tracker on the handsets, is that newer versions of Android fall back to using port 443 (the standard HTTPS port) which most firewalls allow traffic through by default. This is how our devices running newer Android versions are working even behind the firewall. I don't know precisely what Android version introduced this port 443 fallback, but it's somewhere between 4.1.2 (not working) and 4.3 (working).

Firebase cloud messaging notification not received by device

You have placed your service outside the application tag. Change bottom to this.

<service
android:name=".NotificationGenie">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

</application>

Google Cloud Messaging - messages sometimes not received until network state changed

I've noticed this as well. Although I haven't dug into the actual code, here's my understanding of why this happens.

GCM (and most push messaging services) works by keeping a long-lived socket open to Google's push notification server. The socket is kept open by sending "heartbeat" messages between the phone and server.

Occasionally, the network state may change and this socket will be broken (because the IP address of the device changes, from 3g to wifi, for example). If the message comes in before the socket is reestablished, then the device will not immediately get the message.

The reconnection only happens when the phone notices the socket is broken, which only happens when it tries to send a heartbeat message.

Again, just my basic understanding of how it works and why it happens, and I could be wrong.



Related Topics



Leave a reply



Submit