Direct MQTT vs MQTT over WebSocket

Takahiko Kawasaki picture Takahiko Kawasaki · Jun 3, 2015 · Viewed 40.8k times · Source

What are merits of MQTT over WebSocket compared to direct MQTT?

I'm considering using MQTT in my project and so I want to know why some people choose MQTT over WebSocket instead of direct MQTT.

Answer

hardillb picture hardillb · Jun 3, 2015

You should only need to run MQTT over websockets if you intend to publish/subscribe to messages directly from within webapps (in page).

Basically I would run pure MQTT for everything and only add the websockets if you actually need it.

For all the none browser languages the MQTT client libraries only use native MQTT. For Javascript there is both a pure MQTT library and the Paho in page library that uses websockets.

Edit: The firewall tunnelling use case is a valid reason to use MQTT over websockets and since writing this answer more of the none web/JavaScript client libraries have added support