Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Using Paho Android MQTT service.


The connect operation is async and may be not completed the time you call publish, since you've commented out the waitForCompletion
Anyway, the mqtt client library do lack some validations to prevent user from wrong API usage, we will improve this.

So you should wait for the connect completion by increasing the timeout or do publish on a IMqttActionListener callback.

Best Regards,
Bin Zhang(张斌)
WebSphere MQ, IBM China Software Development Lab
Notes:   Bin BJ Zhang/China/IBM
E-Mail:  zhbinbj@xxxxxxxxxx
Address: Ring Building 3F, ZhongGuanCun Software Park,

DongBeiWang West Road No.8, Haidian District, Beijing, 100193, China

Inactive hide details for ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) ---07/17/2014 03:13:05 PM---Hi, I am ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) ---07/17/2014 03:13:05 PM---Hi, I am new to Android. Also, I hope, I am using the right forum. Can you

From: ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) <nageshblore@xxxxxxxxx>
To: General development discussions for paho project <paho-dev@xxxxxxxxxxx>
Date: 07/17/2014 03:13 PM
Subject: [paho-dev] Using Paho Android MQTT service.
Sent by: paho-dev-bounces@xxxxxxxxxxx

I am new to Android. Also, I hope, I am using the right forum. Can you please guide me how to use the Android MQTT service for publish and subscribe ?

I have built the Android service JAR successfully with the Paho MQTT client 1.0.0. Also, I have been able to get the Android sample (the one that comes with Android service download) on my Samsung Galaxy phone.

In the onClick() method for a button in my layout, after validations, I am doing the following:

1. Obtain a new MqttAndroidClient instance (c) with context, broker URL and client Id.
2. Do IMqttToken tok = c.connect(); This works as I can see mosquitto broker log this connection.
3. tok.waitForCompletion(3000); This fails with due to a time out.

I commented out the waitForCompletion and went straight for publishing.
1. c.publish(topic, msg). This causes a NullPointerException that points to MqttAndroidClient.publish().


paho-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

GIF image

Back to the top