MQTT over websocket for Android and iOS

2019-07-05 05:26发布

问题:

After a lot of research I settled on MQTT protocol for communication between devices. To take it a step further I thought it would be great to use MQTT over WebSockets. On the server side I'll be using Mosquitto which supports WebSockets. But for the client side, I'm not sure if there are any libraries available for Android and iOS.

Any idea on how to implement it ? or may be any workaround ?

回答1:

If you're using iOS, I would recommend to look at the excellent MQTT-Client-Framework library. You can read about all features and how to use it here: http://www.hivemq.com/mqtt-client-library-encyclopedia-mqtt-client-framework/



回答2:

If it's websockets then it's going to be the Paho Javascript library.

Unless for some reason you want to do websockets from native code rather than from an embeded web page? 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*).

Why do you want to user MQTT over Websockets from native code?

* IBM Message Sight for example.

EDIT:

Also if you want something that "feels" native, but uses the Websocket library you could looks at using something like 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