Paho连接丢失永不触发

时间:2019-02-19 11:06:27

标签: java mqtt paho

以下是我的代码:

 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连接,但没有调用此方法(我处于调试模式)。会是什么?

0 个答案:

没有答案