我正在使用适用于 Android 的 Paho MQTT 库,我的应用程序正在交换实时编辑数据。我想在应用程序与代理断开连接时禁用编辑文本,并在重新建立连接时启用它。
第一部分很简单,MqttCallback
有一个 connectionLost
方法,但没有重新连接。此外,在调试连接方法上的 IMqttActionListener
时,我注意到重新连接时不会触发该事件。
所以我的问题是是否有任何方法可以检测重新连接?
最佳答案
看看 MQTTCallback 类的扩展版本 MQTTCallbackExtended .
它有一个在建立连接时调用的方法。
void connectComplete(boolean reconnect, java.lang.String serverURI)
Called when the connection to the server is completed successfully.
Parameters: reconnect - If true, the connection was the result of automatic reconnect. serverURI - The server URI that the connection was made to.
关于Java Paho MQTT 检测重连,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53988935/