eclipse / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
8.93k stars 2.37k forks source link

Client refuses to connect to broker #2566

Open Bencarnicelli opened 2 years ago

Bencarnicelli commented 2 years ago

I'm trying to run the mosquitto broker on a PC and connect with a different PC. Both have mosquitto installed and can run the broker and publish and subscribe locally. When trying to connect to each other I am running mosquitto with the .conf file containing

user mosquitto allow_anonymous true listener 1883

When running mosquitto using the following command it prints the following.

mosquitto -c mosquitto.conf -v

1655161033: mosquitto version 2.0.14 starting 1655161033: Config loaded from mosquitto.conf. 1655161033: Opening ipv6 listen socket on port 1883. 1655161033: Opening ipv4 listen socket on port 1883. 1655161033: mosquitto version 2.0.14 running

Then on the second PC, I use the command

mosquitto_sub -t "#" -h 192.162.20.68 -d -v -I "Test"

It waits almost exactly 21 seconds before printing

Error: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

When sending the same subscription request on the computer running the broker, it outputs the following

Client Test16804 sending CONNECT Client Test16804 received CONNACK (0) Client Test16804 sending SUBSCRIBE (Mid: 1, Topic: #, QoS: 0, Options: 0x00) Client Test16804 received SUBACK Subscribed (mid: 1): 0

And prints any messages sent with mosquito_pub.

The goal is to run code on an ESP32 but that is having a similar issue. I'm hoping that solving this issue will help solve the issue on the ESP32.

I have tried a multitude of different .conf file configurations and I have made sure the computers are running on the same wifi. Please let me know if there is anything else I can try or change

HashimJVZ commented 2 years ago

If the client works in the same system of the broker and not in an client which is in a different system, it would be mostly an issue on the network.

Make sure ports are open on the system which running the broker.

Try disabling the firewall, or allow the specific port (1883). Or maybe you may need to specify port while subscribing from client.

ralight commented 2 years ago

My guess is with the firewall as well.