赞
踩
只有在新建连接成功的时候在会执行这个函数,重连过程不管是否成功都不会执行这个函数。但是通过MQTTAsync_setConnected();接口设置的回调函数,无论是由于什么情况进行了连接,都会执行这个函数。
1.2 onFailure
无论是新建连接,还是重连,只要要连接失败,都会调用调用这个函数
- MQTTAsync_connectOptions connect_options = MQTTAsync_connectOptions_initializer;
-
- connect_options.cleansession = 1;
- connect_options.keepAliveInterval = 10;
- connect_options.connectTimeout = 10;
-
- connect_options.automaticReconnect = 1;
- connect_options.minRetryInterval = 1;
- connect_options.maxRetryInterval = 30;
-
- /*
- * 只有新建连接才会执行这个函数,重连不会执行
- */
- connect_options.onSuccess = connect_options_success;
-
- /*
- * 如果无论是重连,还是连接失败都会调用这个函数
- */
- connect_options.onFailure = connect_options_failure;
- connect_options.context = handle;
-
- ret = MQTTAsync_connect(handle, &connect_options);
- LOG_I(async, 0, "MQTTAsync_connect: %d\n", ret);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。