paho.mqtt.java
paho.mqtt.java copied to clipboard
Timeout for waiting for CONNACK
- [x] Bug exists Release Version 1.2.0 ( Master Branch)
After establishing a TCP connection to a broker and sending the CONNECT message, the client will wait for a CONNACK message indefinitely. There should be a timeout for not receiving the CONNACK message within a specific period.
To make it more precise: I have a problem when I try connect to a TCP server which does not support MQTT. The server does not close the connection and the client waits for a CONNACK. I did also not figure out to stop the client in any wait, since close throws an exception and disconnect never terminates.
Hi,
You when you use connect, you will get a IMqttToken back, if you then call waitForCompletion(<time in milliseconds>);, then it will wait for the client to either complete the connection, or for the timeout, whichever is first.
Then you can simply check isConnected() on the client and you will be able to tell if it failed or succeeded.
I'm using callbacks when connecting, but they will never be called due to this problem. I'd prefer to not block on waitForCompletion().
Concerning this issue, the absence of timeout for connack is especially troublesome when it comes to reconnection. That is, we don't have to access to IMqttToken at the time of recconection. Do you guys have ideas to deal with connack timeout properly for reconnection?
Relates to: https://github.com/eclipse/paho.mqtt.java/issues/856