简体   繁体   English

适用于Android和iOS的websocket上的MQTT

[英]MQTT over websocket for Android and iOS

After a lot of research I settled on MQTT protocol for communication between devices. 经过大量研究,我决定使用MQTT协议进行设备之间的通信。 To take it a step further I thought it would be great to use MQTT over WebSockets. 为了更进一步,我认为在WebSockets上使用MQTT会很棒。 On the server side I'll be using Mosquitto which supports WebSockets. 在服务器端,我将使用支持WebSockets的Mosquitto。 But for the client side, I'm not sure if there are any libraries available for Android and iOS. 但对于客户端,我不确定是否有适用于Android和iOS的库。

Any idea on how to implement it ? 有关如何实现它的任何想法? or may be any workaround ? 或者可能是任何解决方法?

If you're using iOS, I would recommend to look at the excellent MQTT-Client-Framework library. 如果您使用的是iOS,我建议您查看优秀的MQTT-Client-Framework库。 You can read about all features and how to use it here: http://www.hivemq.com/mqtt-client-library-encyclopedia-mqtt-client-framework/ 您可以在此处阅读所有功能及其使用方法: http//www.hivemq.com/mqtt-client-library-encyclopedia-mqtt-client-framework/

If it's websockets then it's going to be the Paho Javascript library . 如果它是websockets,那么它将成为Paho Javascript库

Unless for some reason you want to do websockets from native code rather than from an embeded web page? 除非由于某种原因你想从本机代码而不是从嵌入式网页做webockets? I'm not sure there are any native libraries for using MQTT over websockets, but I also can not think of a good reason to do it (bar only having on port open on the broker may be, and even then some broker implementations share the port * ). 我不确定是否有任何本地库在websockets上使用MQTT,但我也想不出有一个很好的理由(只有在代理上打开端口可能,甚至一些代理实现共享港口* )。

Why do you want to user MQTT over Websockets from native code? 为什么要从本机代码通过Websockets使用MQTT?

* IBM Message Sight for example. * IBM消息照准例如。

EDIT: 编辑:

Also if you want something that "feels" native, but uses the Websocket library you could looks at using something like Apache Cordova 此外,如果您想要“感觉”原生的东西,但使用Websocket库,您可以使用像Apache Cordova这样的东西

Second Edit: 第二编辑:

Things have moved on a lot since this anser was first written (back in 2014), the Paho Java library now support MQTT over Websockets and this library is used to underpin the Paho Android library allowing native (node web) code to connect to brokers supporting MQTT over Websockets 自从这个anser首次编写(早在2014年)以来,事情发生了很大变化,Paho Java库现在通过Websockets支持MQTT,这个库用于支持Paho Android库,允许本机(节点web)代码连接到支持经纪人MQTT over Websockets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM