简体   繁体   中英

Why use MQTT Node.JS library?

I am currently building a web app using the Paho MQTT Javascript library, and I was wondering in what case should I use the MQTT.JS library ? Could you give me examples when I cannot use the Javascript library and need to use the MQTT.js library (which I think is made for Node.js) ?

(I know the two things are completely different but still, they both concern web applications!)

Thank you !

The Paho JavaScript client is specifically targeted for use in client side (in the browser) and uses MQTT over Websockets to connect to MQTT brokers that support this transport layer. It is the reference implementation for MQTT over Websockets.

Assuming you mean the MQTT.js package when talking about the "Node.JS one" this is a pure javascript implementation of the a MQTT client that can use either native MQTT or MQTT over Websockets when used with Node.JS to build client applications. It can also be used with a tool such as Browserify and Webpack then it can be packaged to be used in the web browser to connect to a MQTT broker using MQTT over Websockets

When you choose to use each depends on what you are trying to do, if you are purely writing a web client solution then the Paho library will meet your needs. If you are writing a Node.JS application then obviously then the MQTT.js is the correct choice. If you are writing both then there may be some merit in using the MQTT.js library in the both places to ensure consistency.

when you use mqtt broker, you should install npm package of mqtt, that package you can get from node.js.

using command : npm install mqtt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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