直到网络状态改变

直到网络状态改变

本文介绍了谷歌云消息 - 消息有时没有收到,直到网络状态改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然工作的一个小项目,与GCM集成,我已经跨越了一下一个奇怪的问题栽了跟头。

While working on a little project that integrates with GCM, I've stumbled across a bit of a strange issue.

当我开始观看日志,查看是否收到消息,消息似乎并没有现身过,直到我已经改变了网络状态(即原来的无线网络,如果我关闭WiFi和移动到移动数据有些时候,在邮件到达罚款)。之后,我已经改变了网络状态,消息陆续抵达完全正常,这同样适用一旦我改变了网络状态恢复到它以前(在这种情况下,无线网络)的消息将继续被接收。

Some times when I start watching the log to see if messages are received, messages do not appear to be coming through until I have changed the network state (I.E. originally on WiFi, if I turn off WiFi and move to Mobile Data, the messages arrive fine). After I've changed the network state, messages start to arrive perfectly fine, and the same applies once I change the network state back to what it was before (in this case, WiFi) the messages continue to be received.

该项目本身包括在引导时启动的能力(在开始启动的GCMBaseIntentService),这再次工作完全正常,而且我敢肯定,应用程​​序/服务正在运行,因为我已经手动启动应用程序时,这个问题发生(也检查是否该服务正在运行,如果不是它运行它,并检查它是否已注册)。

The project itself includes the ability to start on boot (starts the GCMBaseIntentService on boot), which again works perfectly fine, and I'm sure the app / service is running as I've manually started up the app when this issue occurs (which also checks to see if the service is running, and if it's not it runs it and checks to see if it's registered).

有没有其他人遇到这个问题,或有任何指标,让我怎么能解决呢?我没有看到的消息的时间之间的日志中有很大帮助什么都没有收到,当他们(改变网络状态后)。我已经通过了GCM文档消失了,看不到任何提及未因收到超时或任何配置选项(在设备上)的消息可能会影响到这一点,。

Has anyone else come across this issue, or has any pointers as to how I could resolve this? I'm not seeing anything of much help in the log between the time messages are not being received and when they are (after changing the network state). I've gone through the GCM docs and can't see any mention of messages not being received due to a time-out (on the device itself), or any config options that might affect this.

鸭preciate任何帮助 - 我可以提供源代码如果需要的话,尽管它很难从Android的SDK提供的演示程序偏离

Appreciate any assistance - I can provide source if needs be, although it hardly deviates from the demo app provided in the android-sdk.

推荐答案

我已经注意到了这一点。虽然我没有挖成实际的code,这是我的,为什么出现这种情况的了解。

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

GCM(最推送消息服务)的工作原理是保持长寿的插座开放给谷歌的推送通知服务器。插座保持通过发送手机与服务器之间的心跳的消息公开。

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.

有时候,网络状态可能会发生变化,这种插座将被打破(因为设备的IP地址更改,从3G到无线网络,例如)。如果消息来自插座重新建立之前,则该设备将不会立即得到消息。

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.

这篇关于谷歌云消息 - 消息有时没有收到,直到网络状态改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 12:42