MQTT : Web Socket in python

0 votes

So, I'm trying to connect with this code but this paho library does not work for it.

 import sys
 import paho.mqtt.client as mqtt

 def on_connect(mqttc, obj, flags, rc):
     print("rc: "+str(rc))

 def on_message(mqttc, obj, msg):
     print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))

 def on_publish(mqttc, obj, mid):
     print("mid: "+str(mid))

 def on_subscribe(mqttc, obj, mid, granted_qos):
     print("Subscribed: "+str(mid)+" "+str(granted_qos))

 def on_log(mqttc, obj, level, string):

 mqttc = mqtt.Client()   
 mqttc.on_message = on_message
 mqttc.on_connect = on_connect
 mqttc.on_publish = on_publish
 mqttc.on_subscribe = on_subscribe
 mqttc.connect("", 8080, 60)
 mqttc.subscribe("test/iot", 0)


Is there support in python to subscribe to the MQTT broker with port 8080?

Apr 15 in IoT (Internet of Things) by Upasana
• 7,560 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can simply create a configuration file for example in


with the following contents:

listener 1883
protocol mqtt

listener 9001
protocol websockets

then run mosquito with the following

mosquitto -c /etc/mosquitto/mosquitto.conf

You should get this output:

1469015320: mosquitto version 1.4.8 (build date 2016-05-3112:07:40+0200) starting
1469015320: Config loaded from /etc/mosquitto/mosquitto1.conf.
1469015320: Opening ipv4 listen socket on port 1883.
1469015320: Opening ipv6 listen socket on port 1883.
1469015320: Opening websockets listen socket on port 9001.

Your python client then connects to port 1883 and the browser client to 9001

answered Apr 15 by Shubham
• 12,150 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Changing message format in KURA MQTT cloud client

The Eclipse Kura communicates with a MQTT ...READ MORE

answered Jul 29, 2018 in IoT (Internet of Things) by DataKing99
• 8,100 points
0 votes
1 answer

Publishing commands to device in IBM IoT using MQTT in Java

If you are publishing from an application, ...READ MORE

answered Jul 27, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
0 votes
1 answer

The MQTT folder is missing in Bluemix IoT NodeJS code,

IoT-Workbench now uses new improved code generation ...READ MORE

answered Aug 8, 2018 in IoT (Internet of Things) by anonymous2
• 4,260 points
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
0 votes
1 answer

PWA : Using Bluetooth in my phone in Progressive Web Apps

Yes, you can access in Geo Location(for ...READ MORE

answered Dec 20, 2018 in IoT (Internet of Things) by Shubham
• 12,150 points
0 votes
1 answer

Paho MQTT : Exception in Thread

So, I'd reckon you try to take a ...READ MORE

answered Apr 4 in IoT (Internet of Things) by Shubham
• 12,150 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.