Open acetylen opened 5 years ago
From my understanding the code is supposed to return 0.
The intention is definitely to use the on_connect and on_disconnect callbacks.
I think the behaviour might be residues from ancient times of this library (i.e. to maintain compatibility and not break too many things).
@PierreF @ralight can any one you confirm so we can close this issue?
My problem is specifically that I'm dealing with a system that runs a non-standard broker, that doesn't signal failure properly. If the client provides bad credentials, the broker holds the connection open until the other side times out. This makes it hard to use the callbacks as none of them fire, and it also makes it hard to use connect
as it returns immediately. With is library there's basically no way to know failure state.
that doesn't signal failure properly.
So, if I'm understanding you correctly, the broker does not return a CONNACK
or drop the connection?
The only real option the spec offers in this situation is a timeout:
If the Client does not receive a CONNACK Packet from the Server within a reasonable amount of time, the Client SHOULD close the Network Connection. A "reasonable" amount of time depends on the type of application and the communications infrastructure.
I've had a scan through the library and there does not seem to be any option for a CONNACK
timeout; as such I'm going to tage this issue as an enhancement request.
Summary
The
paho.mqtt.client.Client.connect()
function call always returns zero, even on failed connections.If the intention is to use the
on_connect
andon_disconnect
callbacks, then surely theconnect
method should not return anything? This behavior is needlessly confusing.Software
Test setup
mqtt_tester.py
Mosquitto configuration:
Contents of
mqtt_tester.py
:Method
mosquitto -v -c mosquitto.conf
mosquitto_sub -t "#" -v -u testuser -P test
python3 mqtt_tester.py
Test
Case 1: correct credentials
mosquitto -v -c mosquitto.conf
output:python3 mqtt_tester.py
output:mosquitto_sub -t "#" -v -u testuser -P test
output:Case 2: incorrect credentials
for this case, line 5 of
mqtt_tester.py
was changed fromto
No other changes were made.
mosquitto -v -c mosquitto.conf
output:mosquitto_sub -t "#" -v -u testuser -P test
output:python3 mqtt_tester.py
output: