Android的MQTT无法创建客户端 [英] Android MQTT unable to create client

查看:134
本文介绍了Android的MQTT无法创建客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用泛美卫生组织客户端库我的Andr​​oid服务,创建一个MQTT客户机。
该mosquitto经纪人我的本地机器上运行。
我得到一个MqttPersistenceException例外,当我试图创建MQTTClient的新实例。

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.

//创建客户端
端口= 1883年
mqttConnSpec =TCP://+ ipaddressOflocalMachine +:+端口
mqttClient =新MqttClient(mqttConnSpec,mqttClientId)

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

除了不给任何理由。
我能够成功使用Java控制台应用程序进行通信。
有什么在Android模拟器中运行时,这个额外需要的。
任何帮助深表AP preciated

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

谢谢

推荐答案

你能分享更多一点的code的 - 你建立一个持久化类

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

有一些讨论它在Android的Java /泛美卫生组织MQTT客户的良好资源。基本的事情是,你需要实现一个持久类或指定内存或文件中的一个提供。这是在<一个讨论href=\"http://stackoverflow.com/questions/10065624/how-to-send-ping-using-ecipse-paho-mqtt-client\">another StackOverflow的答案。另请参见这个错误,这解释说,你需要确保用户.DIR设置或使用不同的持久性方法。还有更多的资源对MQTT维基一个列表。

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.

这篇关于Android的MQTT无法创建客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆