-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added a connection timeout callback #523
Comments
From #521 -
|
support can set the callback when the connection times out
|
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. |
for example
I set the timeout to 10 s, then I will get a callback after 10 s,
This way I can solve it,If the total connection time exceeds 10S, I can manually disconnect and manually connect it
The text was updated successfully, but these errors were encountered: