Mosquitto broker set up issue

I follow up the tutorial to set up the mosquitto broker on window
steps:-
1)download the broker from website
2)install it
3)change in config file to run the broker on local IP
listener 1883 0.0.0.0
max_packet_size 10000
allow_anonymous true
4)Windows Defender Firewall->advanced setting->inbound rules->new rule->make TCP port 1883
5)services->mosquitto broker ->automatic

command prompt

C:\Program Files\mosquitto>net start mosquitto

The Mosquitto Broker service was started successfully.

C:\Program Files\mosquitto>mosquitto_sub -h localhost -t test
Error: No connection could be made because the target machine actively refused it.

when manually start the mosquitto broker by services i got this …

the mosquitto broker services on local computer started and then stopped .some services stopped automatically if thay are not in use by other services or program

please reply ASAP ,thank you
any help will be appreciated

Hello,

Some things to check:

  • Can you set the logs of your broker to log_tye all and check the logs, please?

  • Further, can you check if only Mosquitto is using the port 1883 on that machine? So there are no port conflicts.

mosquitto -c "C:\Program Files\Mosquitto\mosquitto.conf" -v > mosquitto.log 2>&1

I make mosquitto.log successfully when I opened it. I got this
1718003183: Error: Unable to open log file C:\Program Files\Mosquitto\mosquitto.log for writing.
^C

C:\Program Files\mosquitto> sc start mosquitto

SERVICE_NAME: mosquitto
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 10392
FLAGS :

C:\Program Files\mosquitto>mosquitto_pub -i mosq_pub1 -t “Test topic” -m “Test message” -d
Client mosq_pub1 sending CONNECT
Client mosq_pub1 received CONNACK (0)
Client mosq_pub1 sending PUBLISH (d0, q0, r0, m1, ‘Test topic’, … (12 bytes))
Client mosq_pub1 sending DISCONNECT

C:\Program Files\mosquitto>mosquitto_sub -i mosq_sub1 -t “Test topic” -d
Client mosq_sub1 sending CONNECT
Client mosq_sub1 received CONNACK (0)
Client mosq_sub1 sending SUBSCRIBE (Mid: 1, Topic: Test topic, QoS: 0, Options: 0x00)
Client mosq_sub1 received SUBACK
Subscribed (mid: 1): 0
Client mosq_sub1 sending PINGREQ
Client mosq_sub1 received PINGRESP

To activate the logs in windows you have to allow the “write” rule for that folder in the folder settings. It is a windows permission problem, that can appear. The logs are important for debugging.

On the other hand, I do not see a problem in your statements here:

C:\Program Files\mosquitto>mosquitto_pub -i mosq_pub1 -t “Test topic” -m “Test message” -d
Client mosq_pub1 sending CONNECT
Client mosq_pub1 received CONNACK (0)
Client mosq_pub1 sending PUBLISH (d0, q0, r0, m1, ‘Test topic’, … (12 bytes))
Client mosq_pub1 sending DISCONNECT

C:\Program Files\mosquitto>mosquitto_sub -i mosq_sub1 -t “Test topic” -d
Client mosq_sub1 sending CONNECT
Client mosq_sub1 received CONNACK (0)
Client mosq_sub1 sending SUBSCRIBE (Mid: 1, Topic: Test topic, QoS: 0, Options: 0x00)
Client mosq_sub1 received SUBACK
Subscribed (mid: 1): 0
Client mosq_sub1 sending PINGREQ
Client mosq_sub1 received PINGRESP

The clients do connect and send packages.
I am not sure, what your problem is exactly.

Further, I do not think the error message you provided exists in mosquitto. How do you get this exactly?
Error: No connection could be made because the target machine actively refused it.

This problem is solved now .
I have given the folder read and write permission…

but I can’t see the message content

Have you subscribed while you are publishing? You only receive messages, if both the Sub and Pub are online at the same time.

You could set the retain flag for a publish, then you can first publish and then subscribe and still get the last message on a topic.