简体   繁体   中英

Error: read ECONNRESET when connecting from mqtt node.js

I am facing an issue when trying to connect to mqtt broker, I have installed the mosquitto and given two ports(1883,8883) as a listener in the mosquitto.conf file. When I try to run the code for connect from node.js for mqtts on port 8883 I get below error

Error: read ECONNRESET

and on mosquitto

socket error on client <unknown> disconnecting

When I try to publish a message using MQTT.fx it successfully publish the mesasge on port 8883

Below is my code

const config = {
  endpoint: 'mqtts://192.168.0.0',
  topic: 'test/topic/local',
  payload: {message: 'HelloWorld'},
}
mqtt.connect(config.endpoint, {
                    clientId: 'some id',
          })

Are there some configurations needs to be done?

mqtts is the tls version of mqtt , to use it you will need to either supply certs to match the backend or configure it not to validate if they are self signed.

to disable validation add this to your connect

rejectUnauthorized: false

be aware that doing this will prevent your client from being able to validate the backend safely, you should never do this in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM