以下是我的代码:
public void connect() throws MqttException {
MqttConnectOptions options = new MqttConnectOptions();
options.setUserName("user");
options.setPassword("pass".toCharArray());
options.setAutomaticReconnect(true);
MqttClient client = new MqttClient("tcp://broker:8884", MqttClient.generateClientId(), handlerPahoDirs());
client.setCallback(callback);
client.connect(options);
client.subscribe(this.topic);
}
和connectionLost
在 MqttCallback 上:
public void connectionLost(Throwable throwable) {
try {
connect();
} catch (MqttException e) {
//Logger
}
}
事实证明,connectionLost()
从未被调用!有时,我断开了Internet连接,但没有调用此方法(我处于调试模式)。会是什么?