Receive Android GCM messages so slow?

可紊 提交于 2019-12-02 13:26:47

问题


Google Cloud Messaging (Push message) problem.
I have two smartphones(HTC Sensation XE, Desire HD) and a tablet(Samsung Galaxy Note 10.1 Wifi).
Sometimes I need to wait for almost 15 minutes to receive the GCM push messages. Sometimes I receive the GCM push messages immediately(within 30 secs).
Is it normal? Or just because I'm under Wifi connected?
If it is normal, are there any other services like "long-polling" I can use for retrieving messages from server?
I'm currently using GCM+Polling(AlarmManager) to retrieve messages from remote server.
Any suggestions or better ideas?

Below is my test result:
The left side is server send time, while the right side is client mobile receive time.
All the test results are under Wifi connected environment.
==========================
HD 23:10:18, 23:24:XX

XE 23:11:21, 23:22:44

Note 23:10:20, 23:14:54

==========================
HD 00:08:12, 00:08:27

XE 00:07:55, 00:07:58

Note 00:08:04, 00:13:35

==========================
HD 00:40:21, 00:55:22

XE 00:39:56, 00:40:14

Note 00:40:13, 00:40:59

Thanks!!


回答1:


GCM uses throttling when there's excessive use, see the following document for more details:

http://developer.android.com/google/gcm/adv.html#throttling




回答2:


Please read my answer here:

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

It's basically a tcp timeout problem




回答3:


You can manually trigger the heartbeat to keep the connection alive by the following code. Some network routers will automatically kill the idle socket connections if it is idle for a particular time period (sometimes 5 minutes). Execute the code in every 5 minute so that the connection will be re-established if it is closed. But, obviously reducing the interval will consume bit more battery (I don't know how much it is relevant here because nowadays the smart phones come up with high mAh battery).

getApplicationContext().sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
getApplicationContext().sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));


来源:https://stackoverflow.com/questions/16386602/receive-android-gcm-messages-so-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!