Skip to content
Snippets Groups Projects
Commit 6c944691 authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

Client code

parent f73a98a4
No related branches found
No related tags found
No related merge requests found
......@@ -11,13 +11,14 @@ PORT = 3074
def start_chat_thread(conn, addr):
t = ChatMsgThread(conn, addr)
t.start()
print("Thread created and offloaded connection with IP {}:{}".format(addr[0], addr[1]))
class ChatMsgThread(Thread):
def __init__(self, conn, addr):
Thread.__init__(self)
self.conn = conn
self.addr = addr
print("IP {} connected".format(addr[0]))
#print("IP {} connected".format(addr[0]))
def run(self):
self.conn.sendall(b"Send your message, I will be able to see it here.\n")
......
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
HOST = 'broker.hivemq.com'
PORT = 1883
TIMEOUT = 60
def on_message(client, userdata, message):
print("{}: {}".format(message.topic, str(message.payload)))
def on_connect(client, userdata, flags, rc):
print("Connected.")
client.subscribe('lahtp')
client = mqtt.Client()
client.on_message = on_message
client.on_connect = on_connect
client.connect(HOST, PORT, TIMEOUT)
client.loop_forever()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment