MQTT.js icon indicating copy to clipboard operation
MQTT.js copied to clipboard

Why do I use mqtt protocol to connect, and finally become WS protocol

Open zhong946555 opened this issue 3 years ago • 3 comments

image image

zhong946555 avatar Jun 01 '22 04:06 zhong946555

Can someone help me? I'm a novice. I've been fooled by this for two days

zhong946555 avatar Jun 01 '22 09:06 zhong946555

Hi, got the same problem

kolboss avatar Jun 02 '22 06:06 kolboss

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

doc-han avatar Jun 09 '22 16:06 doc-han

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.

albertphlin avatar Apr 03 '23 16:04 albertphlin

MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues

robertsLando avatar Jul 21 '23 14:07 robertsLando

I have fixed Browser docs by adding webpack and vite setup. Check them out

robertsLando avatar Jul 31 '23 15:07 robertsLando