0

In Android, at the moment when I publish something using MqttAndroidClient, it waits indefinitely. I want to set a timeout for Publish method, so that I know when it has failed to publish.

Please let me know how to add the timeout.

    val mqttClient = MqttAndroidClient(context, BuildConfig.MQTT_URL, clientId, Ack.AUTO_ACK)

    val options = MqttConnectOptions()
    options.userName = BuildConfig.MQTT_USERNAME
    options.password = BuildConfig.MQTT_PASSWORD.toCharArray()
    options.isCleanSession = false
    options.isAutomaticReconnect = false

    mqttClient?.connect(options, object : IMqttActionListener {
                override fun onSuccess(asyncActionToken: IMqttToken?) {}
                override fun onFailure(asyncActionToken: IMqttToken?, exception: Throwable?) {})

I don't see the function setTimeToWait(timeToWaitInMillis); which is available for MqttClient

M. Usman Khan
  • 3,689
  • 1
  • 59
  • 69
  • Does this answer your question? [publish method of the Paho MqttClient blocking forever](https://stackoverflow.com/questions/40866658/publish-method-of-the-paho-mqttclient-blocking-forever) – Brits Oct 17 '22 at 03:29
  • @Brits no. I have added some explanation there – M. Usman Khan Oct 19 '22 at 06:20

0 Answers0