Hello Mehdi. Welcome to the community discussions
for Paho. The component committers are on holiday this week so there may
be some delay in getting you an answer. In the meantime, there may
be someone else on the mailing list who has an answer.
I am quite interested in following the
progress of your application of MQTT on Android.
"Dr. Mehdi Hasan
04/08/2012 03:17 PM
sending ping using Paho MQTT client
First of all, thank you for releasing the source of MQTT
client code. We've just started building our own push notification system
for Android and found this gem. Needless to say, this Eclipse Paho project
is really exciting.
The problem with Android is, if the CPU is in sleep state,
the client may not get the chance to send ping at its set interval. The
workaround is using AlarmManager to wake it up and get the job done. The
Android documentation says: "The
Alarm Manager holds a CPU wake lock as long as the alarm
receiver's onReceive() method is executing. This guarantees that the phone
will not sleep until you have finished handling the broadcast. Once onReceive()
returns, the Alarm Manager releases this wake lock. This means that the
phone will in some cases sleep as soon as your onReceive() method completes."
I need to be sure that I could send the ping command within
that onReceive() method while the CPU hasPARTIAL_WAKE_LOCK, so I
was searching a way to manually sending ping to server but it seems the
client doesn't expose any such method. Am I missing something? Or, what
is the workaround here except publishing my own "ping message"?
I want to avoid that because of:
1. Larger overhead
2. We'll ensure that Android clients are subscriber
only, may be with Mosquitto's ACL. They will not be allowed to publish