paho.mqtt.client.connect() with localhost or 127.0.0.1

42 views
Skip to first unread message

jaybr...@gmail.com

unread,
Apr 26, 2018, 12:44:51 PM4/26/18
to MQTT
The following call (I imported paho.mqtt.client) works if BROKER_ADDR is assigned a specific IP address, but fails if it is assigned 127.0.0.1 or localhost (out of desperation I even tried 0.0.0.0)

client.connect(
BROKER_ADDR, 1883)

Has anyone else encountered or solved this problem?

Note that I also tried importing socket and using socket.gethostbyname(socket.gethostname()) but that just returns 127.0.0.1

Thanks

ran...@bevywise.com

unread,
Apr 27, 2018, 1:44:21 AM4/27/18
to MQTT

What is the Broker you are using and what is the OS?  

 By default all MQTT Broker should run on 0.0.0.0 IP making it available for all the local loopback addresses and the public IP of the machine.  But on the client side you should use either the IP Address or the localhost address and you cannot use 0.0.0.0 in your client.  

There may be some firewall restrictions added in your OS for the localhost for connecting. 

Try doing telnet localhost 1883 or telnet 127.0.0.1 1883. If this connection happens, the Paho client should be able to connect. 

Cheers, 
Ranjith 
Bevywise Networks. 
Reply all
Reply to author
Forward
0 new messages