amonchakai / Hg10

Hg10 -- A XMPP Client for BlackBerry 10 (aiming Google Talk)
20 stars 11 forks source link

[Bug?] Failed to send and receive messages after a long time airplane mode #49

Closed pedbg7 closed 9 years ago

pedbg7 commented 9 years ago

Hi, First many thanks to your hard work!

I find that the app cannot send or receive any messages after a long time airplane mode. I turn on the airplane mode before my sleep and turn it off the second day morning. However, the app can still pull history from Google server by clicking on a contact that I haven't clicked before.

I tracked down a little bit in Momentics and find that:

Hg10Service/src/XMPPService.cpp: void XMPP::readyRead() { case XMPPServiceMessages::SEND_MESSAGE: { sendPacket(QXmppMessage("", to, message)) }

The "sendPacket()" has been successfully called in my debug console. So I guess there is a problem in the underlying layer?

pedbg7 commented 9 years ago

By the way, a short duration of airplane mode like a few minutes is fine.

amonchakai commented 9 years ago

Hello!

I solved this issue in the latest beta. I should have checked what sendPacket() replies: it sends false if it does not succeed to send the message. And if it does not work, then I guess it must reconnect to the server. That is my current solution.

But it also reveals that previous checks did not work: when you open a conversation, I first check the status of the link to the server. And then, if it is not connected, I try to reconnect.

However, sometimes it seems that it does not work... It depends on the ability to detect that the connection failure to the XMPP server. To address this, there is signal "disconnected()" sent by the QXMPPClient. But I wonder if it is me who is not processing it correctly or if the signal is really sent. It is hard to debug as I suspect that there is some delay between the loss of internet access and the time the QXMPPClient realize it is not connected anymore to the server.

So for the moment, I just added a backup solution to recover from errors: if the message is not sent -> it must be disconnected -> try to reconnect.

(and I will need to add a stack of not sent messages, to try to send them again once reconnected)

pedbg7 commented 9 years ago

Hi,

Sounds a reasonable solution! I'm wondering if it is possible to send a "heart beat" packet to Google every 5 or 10 minutes? So the disconnection window can be minimized to this long.

Otherwise, we don't know when the connection is lost until we send something, i.e, we won't get the incoming messages at the same time.

amonchakai commented 9 years ago

I think these "heart beat" packets should be handled by the QXMPP library. And that is why it may takes some time before it realizes a connection drop. But maybe there is a setting I missed.

Do you have a lot of problems with it? You mentioned the airplane mode, I guess there must be a signal from the OS indicating whether it is ON or OFF. I should probably catch it, that would solve your issue.

I could also do the same for the internet access in general, it seems like a good idea.

EDIT: Yup, there is something: https://developer.blackberry.com/native/documentation/device_comm/networking/index.html And that would be a nice way to address my energy consumption issues :)