Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do not receive GCM message while android device being connected to WIFI

Background

I am working on an Android app which uses Google Cloud Messaging (new GCM-API, not deprecated C2DM) for sending send-to-sync messages to all registered devices.

Since I used the official documentation my client implementation works almost exactly the same way like Google´s example. As a server I use a simple PHP script running on localhost whose only task is to send send-to-sync messages to GCM.

The Issue

Everything works fine as long as my devices are connected to the internet through cellular networks like UMTS (server sends notfication to GCM > GCM pushes notifcation to device as soon as it is online > notification is displayed on device).

But when the device is connected to the WIFI no GCM messages will be received anymore (although Google sends a "success"-reply to my PHP server). Due to the following answer I have already checked if my router blocks some ports but it does not.

I had same problem of receiving push messages, even though GCM server replies "Success", because of wifi privacy. When I used my company wifi, I coudn't receive message in mobile, since they were blocked GCM server port.

Interestingly enough my implementation already has been working with WIFI...

Google´s reply when sending GCM message from PHP:

{
    "multicast_id":4677038582377051331,
    "success":1,
    "failure":0,
    "canonical_ids":0,
    "results":[{"message_id":"0:1406364179145476%6ce83c64d7d6c7e2"}]
}


Very crazy finding:

The issue solved itself when I called the PHP script which sends my GCM messages from the smartphone and since that everything works fine.

HINT

Meanwhile this "new" GCM-API is deprecated either! I am using the latest GCM-API (published in summer 2015) now. Since upgrading I have never faced this issue again. The new API, including InstanceId-API is very recommendable from my point of view, as far as I see it is a more stable than old GCM.

like image 803
sschmid Avatar asked Jul 26 '14 09:07

sschmid


Video Answer


1 Answers

You need to open ports 5228 - 5230 to make GCM work properly.

Check the following:

Note: If your organization has a firewall that restricts the traffic to or from the Internet, you'll need to configure it to allow connectivity with GCM. The ports to open are: 5228, 5229, and 5230. GCM typically only uses 5228, but it sometimes uses 5229 and 5230. GCM doesn't provide specific IPs. It changes IPs frequently. We recommend against using ACLs but if you must use them, take a broad approach such as the method suggested in this support link.

If your Company Wifi does not allow these ports then you will not be able to receive GCM.

Hope it helps

like image 134
zozelfelfo Avatar answered Oct 14 '22 21:10

zozelfelfo