有谁知道在Android智能手机上运行的MQTT代理?我试图谷歌并没有发现任何东西,并且在应用程序商店中似乎只有一个应用程序只有10次下载,所以我不确定它的工作情况。
将这些依赖项添加到gradle中
dependencies{
compile 'io.moquette:moquette-netty-parser:0.8.1'
compile 'io.moquette:moquette-broker:0.8.1'
compile 'io.moquette:moquette-parser-commons:0.8.1'
}
并使用
io.moquette.server.Server server = new io.moquette.server.Server();
server.startServer();
启动代理服务器。默认URI是tcp://localhost:1883
对我来说,server.startServer();
给了我例外,因为它无法创建文件BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME
。所以,我使用代码下面的代码更改了BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME
的目的地,它对我有用。
try {
MemoryConfig memoryConfig = new MemoryConfig(new Properties());
memoryConfig.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME);
server.startServer(memoryConfig);
// server.startServer();//is not working due to DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
Log.d(TAG,"Server Started");
}
catch (IOException e) { e.printStackTrace(); }
catch (Exception e){ e.printStackTrace(); }
并使用Paho库为Android
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
创建客户端并连接到tcp://localhost:1883
并订阅主题并开始发布和接收消息。
这是我已经适应Android的MQTT代理库:https://github.com/interaktionsbyran/moquette你必须制作自己的Android应用程序,它只是一个库。
我专门为此开发了一个应用程序,请在此处下载 -
它有内置的经纪人和客户端..所有免费,通过热点或WiFi将您的设备连接到Android手机。
https://play.google.com/store/apps/details?id=server.com.mqtt