MQTT.js
MQTT.js copied to clipboard
Why do I use mqtt protocol to connect, and finally become WS protocol

Can someone help me? I'm a novice. I've been fooled by this for two days
Hi, got the same problem
MQTT is a protocol. A protocol is a set of pre-defined instructions computers use to communicate or understand each other when connected. So MQTT is just a language computers speak when connected. other examples of protocols are HTTP, HTTPS. These are mainly for resource sharing.
Now let's talk about the connection. Computers are able to connect with one another using the TCP/IP internet protocol. So the simple way will be to have the IP of the other computer and then connect with it, After which you'll use another protocol to share resources.
For native use, we are able to use the TCP/IP on a computer(mostly called socket connections) but in the browser, we don't have access to that. Hence, we replace it with WebSockets with seems to work quit similar as that in the browser
In short, mqtt.js only use websockets whatever you set it to mqtt:// or ws://. So, you need to make sure the borker you want to connect has using websockets on that port.
MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues
I have fixed Browser docs by adding webpack and vite setup. Check them out