简体   繁体   English

Google Cloud Messaging(GCM)下游邮件延迟

[英]Google Cloud Messaging (GCM) downstream message delay

I have downloaded and setup the Android gcm-client and gcm-demo-server (http server) from http://code.google.com/p/gcm/ . 我已经从http://code.google.com/p/gcm/下载并安装了Android gcm-client和gcm-demo-server(http服务器)。 I have managed to receive downstream messages in my Android gcm-client app. 我已经设法在我的Android gcm-client应用程序中接收下游消息。 I have done numerous tests with the following characteristics: 我做了很多具有以下特点的测试:

  1. The server used either a browser API key or a server API key. 服务器使用浏览器API密钥或服务器API密钥。
  2. The data connection was either 3G or WiFi 数据连接是3G或WiFi
  3. The sent message included/didn't include additional data. 发送的消息包含/不包含其他数据。
  4. The sent message had/didn't have a collapse key. 发送的消息有/没有折叠键。
  5. The sent message had delayWhileIdle set to false. 发送的消息将delayWhileIdle设置为false。
  6. The sent message had timeToLive set to 0 or 5 minutes. 发送的消息将timeToLive设置为0或5分钟。
  7. The server was located in two different locations within Europe. 该服务器位于欧洲的两个不同位置。
  8. The Android app run in two devices located in different places within Europe. Android应用程序在位于欧洲不同地方的两台设备上运行。

In all cases the app receives the sent messages after 25-30 sec from the moment they were sent. 在所有情况下,应用程序会在发送后25-30秒之后收到已发送的消息。 However, I have tested other Android applications that use GCM downstream messages and in most cases the messages arrive almost instantly (<5sec). 但是,我测试了其他使用GCM下游消息的Android应用程序,在大多数情况下,消息几乎立即到达(<5秒)。

Is there something I can change in the client or server in order to have the messages received in the app sooner? 我可以在客户端或服务器中更改某些内容,以便更快地在应用程序中收到消息吗?

I also tried to use the gcm XMPP server (Java application using Smack) given in http://developer.android.com/google/gcm/ccs.html but I didn't manage to sent any messages. 我还尝试使用http://developer.android.com/google/gcm/ccs.html中提供的gcm XMPP服务器(使用Smack的Java应用程序),但我没有设法发送任何消息。 The response I receive from GCM Cloud Connection Server (CCS) says "Project XXXXXXXXXX not whitelisted". 我从GCM Cloud Connection Server(CCS)收到的回复显示“项目XXXXXXXXXX未列入白名单”。 The most possible reason is that my registration for CCM has not been approved yet as described in Google CCS (GCM) - project not whitelisted . 最可能的原因是我的CCM注册尚未获得批准,如Google CCS(GCM)所述 - 项目未列入白名单 As I have read in various websites, the approval usually takes more than 2-3 months, so I will most possibly not be able to test the XMPP server soon. 正如我在各种网站上看到的,批准通常需要2-3个月,所以我很可能很快就无法测试XMPP服务器。

Is it possible that you can only receive nearly instant messages by using an XMPP server? 是否有可能只能使用XMPP服务器接收即时消息? Does anybody have any experience of the delays encountered using an XMPP server? 有没有人对使用XMPP服务器遇到的延迟有任何经验?

Thanks in advance 提前致谢

I think that the problem is in the android gcm-client demo that are retaining the message, not in the gcm-server. 我认为问题是在android gcm-client演示中保留了消息,而不是在gcm-server中。 In GcmIntentService.java file of gcm-client demo, it can be seen that the function protected void onHandleIntent(Intent intent) have the following code: 在gcm-client演示的GcmIntentService.java文件中,可以看到函数protected void onHandleIntent(Intent intent)具有以下代码:

[...]
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
    for (int i = 0; i < 5; i++) {
    Log.i(TAG, "Working... " + (i + 1)
            + "/5 @ " + SystemClock.elapsedRealtime());
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
    }
}
[...]

This code sleeps android application 5 seconds every iteration (total 25 seconds) before deliver a notification message. 在发送通知消息之前,此代码每次迭代(总共25秒)睡眠android应用程序5秒。 You can delete this code due to is an example and you can insert into else if statement some work before show notification. 您可以删除此代码,因为这是一个示例,您可以在显示通知之前插入else if语句中的一些工作。

I have implemented a xmpp server and I receive the notification in <5 seconds, without this working code, of course. 我已经实现了一个xmpp服务器,我在<5秒内收到通知,当然没有这个工作代码。

Hope this help and sorry for my bad English. 希望这有帮助,抱歉我的英语不好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM