Android MQTT unable to create client

﹥>﹥吖頭↗ 提交于 2019-12-24 03:08:53

问题


I am trying to create an mqtt client in my android service using the paho client library . The mosquitto broker is running on my local machine. I am getting an MqttPersistenceException exception when i try to create a new instance of the MQTTClient.

//create client port=1883 mqttConnSpec="tcp://"+ipaddressOflocalMachine+":"+ port mqttClient = new MqttClient(mqttConnSpec, mqttClientId)

the exception does not give any reason. I am successfully able to communicate using a java console app. Is there something extra needed when running this in the android emulator. Any help is much appreciated

thanks Ben


回答1:


Can you share a little more of your code - are you setting up an persistence class?

There are a number of good resources which discuss Java/Paho MQTT clients on Android. The basic thing is that you do need to implement a persistence class or specify the in-memory or file one provided. This was discussed in another StackOverflow answer. Also see this "bug" which explains that you need to ensure that user.dir is set or use a different persistence method. There is a list of additional resources on the MQTT wiki.



来源:https://stackoverflow.com/questions/13407045/android-mqtt-unable-to-create-client

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