-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client <unknown> disconnected due to protocol error. #1021
Comments
same here Any update?
|
Same here! |
So I had the same issue, new mosquitto server installed on OSX with homebrew and using react-native. For some reason no native mqtt connection could be made so I used websockets. You'll need to add to mosquitto.conf bellow
When you start mosquitto it should say:
Then connect using:
Hope this helps someone. |
I was getting the error "Client disconnected due to protocol error" in the below scenario:
Fix: |
Just to add a trail of this, you will also encounter a protocol error if you try to use a subscription_identifier that's not between the allowed range 1 ~ 2^28-1 |
Same Issue for me, when I try to use the Websocket solution it works but i'm not in charge of the mosquitto server. I would like to use native MQTT protocol for this. |
bump? |
seems like a pervasive bug. it might be related to some bugs that have been recently fixed in |
Hello! Any updates on this? I seem to have the same issue. |
I used the 6.9.0 version when I found the bug. |
Yup, this worked. 🎉🎉 |
For working, I had to add this to my
|
Hi Client auto-4CBAFA0E-999-20099-DA44-AB775FF164BC disconnected: Protocol error. before that I'm facing these error this is current log mosquitto.conf -------------- use_identity_as_username true persistence true listener 8883 0.0.0.0 cafile /etc/mosquitto/certs/xyz.pem |
I got this when using The specs disallow usage of wildcard characters in topics, so maybe MQTT.js should throw an error before it is sent? |
Hi. I managed to get MQTT to work over TLS. I also received the protocol error when trying to connect onto the secure port 8883. The problem was with creating the certificates. What fixed it was signing the certificates with the broker ip address as the Common Name. So if your broker is running on "192.56.1.0", you would put "192.56.1.0" as the Common Name for all of the signed certificates. Commands I used to generate the certificates: Make sure that you sign the Common Name properly My mosquitto.conf is as follows:
I ran the broker using: Subscribed to the secure network using: Published to the secure network using: Hopefully this helps someone |
This comment was marked as off-topic.
This comment was marked as off-topic.
i am following your steps but i am in windows i am getting this error |
Try to reproduce the issue with MQTT v5 and feel free to reopen in case the bug persists |
Ok, so I came across the same issue yesterday: the server responded with:
Thankfully, I have full access to both the server and the client, so I started doing a little digging. I was running the script with Bun, so I did:
On a different project in the same monorepo (that was behaving properly), I had this output:
but on my test project which looked like this:
the debug output was:
So, I stepped in the connect function and in So, the tl;dr is that the offending piece of code (at least in my case) is the following:
After printing out the individual parts of the And so, the From what I understand, the second check is there to determine if we are in a web worker context. I didn't have time to go any deeper, but a possible solution for this would be to skip the browser check if the protocol is defined in the options object: assume that the user knows what he is doing and go from there. Cheers! |
@f1234k could you describe the environment from which you are running mqttjs? bun? browser? nodejs? |
@robertsLando It's Bun. The command is The contents of the |
Tested with bun Steps to minimally reproduce the issue:
If the server does not support WS connections, you get the Edit: you can run |
question is how to propely detect bun env and distinguish it from web worker, wouyld you like to submit a PR? |
@robertsLando sure. Let me look into this a bit further. |
@robertsLando Done. |
Hi all, i'm facing the same issue using mqtt library from client side with react. I don't get why using the same code from (for example) Bun, like: // connect to MQTT broker
const client = mqtt.connect("mqtt://localhost:1883");
client.on("connect", () => {
console.log("Connected to MQTT broker");
// subscribe to the topic
client.subscribe("/sensors/temperature");
});
// handle MQTT messages
client.on("message", (topic, message) => {
console.log("Message received: ", message.toString());
}); it works as expected, while using it from client side (browser web-worker i assume) i receive the: Client disconnected due to protocol error. In order to make it work, i had to add the WebSockets protocol on port 8883 on the mosquito conf file, as suggested above. const client = mqtt.connect('mqtt://localhost:8883'})
client.on('connect', () => {
console.log('connected to mqtt broker: ', broker);
}); Can someone please explain to me why this is required from the client side and not from Node/Bun? Thanks in advance to those who will help me! |
On browsers the only protocol that works is websocket, this is not an MQTTjs limitation but it's a browser limitation |
So this means that every mqtt connection is upgraded automatically to a websocket connection from browser, while this does not happen on Machine-to-Machine connection, right?. Is there any way from broker side to apply a port forwarding from mqtt exposed port protocol to the websocket one? |
Correct
It depends on the broker you are using but I think that should be possible |
Thanks for the fast reply and explanation! i'm using Mosquitto, I'll take a look at the documentation if it's possible to do it. |
I am using MQTT and below are options that I am passing to connect
var options = {
keepalive: 10,
clientId: '',
protocolId: 'MQTT',
protocolVersion: 3,
clean: true,
reconnectPeriod: 20000,
connectTimeout: 30 * 1000,
protocol:'mqtt',
rejectUnauthorized: false
}
const client = mqtt.connect('mqtt://192.168.127.13:1883',options); -> my local mosquitto broker
can any one help, why I am getting "Client disconnected due to protocol error."
AB#9368700
The text was updated successfully, but these errors were encountered: