This service was created based on the EMQ X MQTT IoT cloud platform. This article will use the free public MQTT broker provided by EMQ X. Or use CDN addresses directly without installation
Install in the current directory npm install mqtt -save If you have the Node.js runtime environment on your machine, you can install MQTT.js directly using the npm command. This article will use the MQTT.js library to explain WebSocket connections. It is worth mentioning that MQTT.js also has good support for WeChat Mini Program.
Also, it supports MQTT/TCP, MQTT/TLS, MQTT/WebSocket connections. On the Node.js side, it can be installed via global installation and connected via the command line. MQTT.js is a fully open-source client-side library for the MQTT protocol, written in JavaScript and available for Node.js and browsers. Compared to another JavaScript connection library, it has fewer features and is not recommended. Paho is an MQTT client project from Eclipse, and the Paho JavaScript Client is one of the browser-based libraries that uses WebSockets to connect to the MQTT server. 1Ĭhapter 6 of MQTT protocol specifies the conditions the MQTT need to meet for transferring over the WebSocket connection, and is not discussed in detail here.
The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C. WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. WebSocket, the instant communication method for Web applications, is also widely used. In recent years, with the rapid development of the Web front-end, new features of browsers are constantly emerging, more and more applications can be implemented on the browser side through the browser rendering engine.