feat: Added a connection timeout callback
for example
I set the timeout to 10 s, then I will get a callback after 10 s,
mqttClient.timeOut = 10
mqttClient.onConnectTimeOut = (){
print('Failed to connect successfully after more than 10 seconds')
}
This way I can solve it,If the total connection time exceeds 10S, I can manually disconnect and manually connect it
mqttClient.timeOut = 10
mqttClient.onConnectTimeOut = (){
mqttClient.disConnect();
mqttClient.connect()
print('Failed to connect successfully after more than 10 seconds')
}
From #521 -
OK, so are you asking for a callback to be added in between connection attempts, i.e. if maxConnectionAttempts is 5 then you will trigger the callback on each failed connection attempt. If that's the case raise an issue for this documenting exactly what you want and which use case this will help with and I'll mark it as a feature request.
From #521 -
OK, so are you asking for a callback to be added in between connection attempts, i.e. if maxConnectionAttempts is 5 then you will trigger the callback on each failed connection attempt. If that's the case raise an issue for this documenting exactly what you want and which use case this will help with and I'll mark it as a feature request.
support can set the callback when the connection times out
mqttClient.timeOut = 10
mqttClient.onConnectTimeOut = (){
print('Failed to connect successfully after more than 10 seconds')
}
There is no field on the client named 'timeOut'. Are you saying that you want a 10 second connection timeout which when expired calls the failed connection callback?
If so you can set maxConnectionAttempts to 1 and _connectTimeoutPeriod to 10000, giving a one shot connection attempt that will last for 10 seconds.
What I'm proposing is that the failed connection callback will be called after every failed attempt, in the case above just once after 10 seconds. If you set maxConnectionAttempts to 3 and _connectTimeoutPeriod to 2000, it will be called 3 times each 2 seconds apart. Note that the attempt number is passed to callback so you can see what attempt failed.
I think I'll disable raising of the NoConnectionException if the user supplies a failed connection callback, clearly in this case they want to handle this eventuality in this way, throwing an exception as well just adds to the noise.
I've set maxConnectionAttempts to 1 and with the current configuration it will always reconnect without any errors, and if the connection is more than 5S, there will be no connection timeouts or connection failures
I set the _connectTimeoutPeriod to 10, but after 10 seconds, I don't get any callbacks for connection failures
I'm now in a scenario where I want to set a timeout of 10s, and if it exceeds 10s, a connection failure callback or a connection timeout callback is triggered
'I set the _connectTimeoutPeriod to 10, but after 10 seconds, I don't get any callbacks for connection failures', no it won't do will it until this change is in the client, this is what I'm doing now.
'I've set maxConnectionAttempts to 1 and with the current configuration it will always reconnect without any errors,' this update is meant for when there is no connection, not when there is, the behaviour of the client is different in these cases.
'I'm now in a scenario where I want to set a timeout of 10s, and if it exceeds 10s, a connection failure callback or a connection timeout callback is triggered', as I've said above when this change is in you will be able to set maxConnectionAttempts to 1 and _connectTimeoutPeriod to 10000 and if you supply a failed connection attempt callback you will get the callback triggered after 10 seconds.
Package updated in line with the above commentary and re released at version 10.3.0.
Please see the onFailedConnectionAttempt callback API in the client, there is also an example of usage mqtt_server_client_failed_connection.dart in the examples directory.