MQTT on Android: connection lost

折月煮酒 提交于 2019-12-04 17:42:21

Your Broker could be using the version 3.1.1 of the spec.

Paho 1.0 implements MQTT 3.1.1 as well as the existing MQTT 3.1 specification. While Paho 0.9 implemented just only MQTT 3.1 spec.

You don't have to change the server , please set the protocol version

Blockquote connOpts.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);

@Override
            public void messageArrived(String arg0, MqttMessage arg1)
                    throws Exception {
                // TODO Auto-generated method stub
                TextView txt = (TextView) findViewById(R.id.txt);
                txt.setText(arg1.toString());
            }

It's not in MainThread,so setText will throw Exception.Delete it and try again.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!