Why use MQTT Node.JS library?

天大地大妈咪最大 提交于 2019-12-10 15:34:29

问题


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 !


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/45189164/why-use-mqtt-node-js-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!