mosquitto-client obtain refused connection

Luca Davanzo picture Luca Davanzo · Jul 3, 2014 · Viewed 31k times · Source

I want to use MQTT protocol using mosquitto library.

First of all, I want to do some test installing mosquitto-clients

 sudo apt-get install mosquitto-clients

This program provides two "method":

  • mosquitto_pub
  • mosquitto_sub

Following this instructions I'm trying to submit new topic:

mosquitto_sub -d -t newtopic/test

using default host/port [localhost/1883].

I obtain:

Error: Connection refused

Is too generic as error.. can anyone help me?
Could be is a firewall problem? In this case, how can I check if is this the problem?

I'm using linux ubuntu ( 3.8.0-42-generic #62~precise1-Ubuntu)

nb same behaviour writing custom program using libmosquitto.

Answer

ralight picture ralight · Jul 3, 2014

The default host:port combination for mosquitto_pub/sub is localhost:1883. If you do not have a broker running on your local computer then it will not be able to connect of course.

The solution is to either run the broker on your local computer, or to tell the utilities where to connect. For example:

mosquitto_sub -t newtopic/test -h test.mosquitto.org