有谁知道在Android智能手机上运行的MQTT代理?我试图谷歌并没有发现任何东西,并且在应用程序商店中似乎只有一个应用程序只有10次下载,所以我不确定它的工作情况.
Tej*_*Tej 11
将这些依赖项添加到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'
}
Run Code Online (Sandbox Code Playgroud)
并使用
io.moquette.server.Server server = new io.moquette.server.Server();
server.startServer();
Run Code Online (Sandbox Code Playgroud)
启动代理服务器.默认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(); }
Run Code Online (Sandbox Code Playgroud)
并使用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'
Run Code Online (Sandbox Code Playgroud)
创建客户端并连接tcp://localhost:1883
和订阅主题并开始发布和接收消息.
我专门为此开发了一个App,请在这里下载 -
它也有内置的经纪人和客户端..全部免费,通过热点或 wifi 将您的设备连接到 Android 手机。
https://play.google.com/store/apps/details?id=server.com.mqtt
归档时间: |
|
查看次数: |
22004 次 |
最近记录: |