Home » Eclipse Projects » Paho » MQTT client stops sending PINGREQ packets after receiving a message on its subscription(Paho MQTT- sockets, timeout, PINGREQ, PINGRESP)
MQTT client stops sending PINGREQ packets after receiving a message on its subscription [message #1750846] |
Thu, 29 December 2016 23:17  |
Nicholas John Messages: 2 Registered: December 2016 |
Junior Member |
|
|
So, I am writing a program that works as a proxy for an MQTT client, to allow it to run over a serial-based internet-connected device. This is why you will see the client connecting to localhost.
I have a relatively simple client script:
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code {0}".format(str(rc)))
#print("result code: "+str(rc)+"\nclient1_id: "+str(client))
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("/blah/testing", qos=0)
def on_message(client, userdata, message):
print("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
#client.connect("m2m.eclipse.org", 1883) # 198.41.30.241
print("Connecting to localhost...")
client.connect("127.0.0.1", port=5231, keepalive=15)
client.loop_forever() # Start networking daemon
If I let this run without publishing any messages to that topic (via a separate script), it behaves, and sends out a PINGREQ every 15 seconds, since I set "keepalive" to that value.
As soon as I publish a message to the topic "/blah/testing" (with a separate script), my client will print (after 10-15 seconds) "Received message 'blah' on topic '/blah/testing' with QoS 0" BUT, once this occurs, my client stops sending out any PINGREQ frames, as if the "loop_forever()" networking daemon decided to stop. It will then eventually disconnect due to what I assume is the socket timing out, as my "socket.recv(size)" call in my proxy script that normally receives socket messages from the MQTT client script starts receiving '' or EOF.
ANY IDEAS?
I tried using loop_start() in place of loop_forever(), and in the message callback I tried stopping and starting the daemon again, but I can't seem to figure out the issue. It's my understanding that the loop_<whatever>() functions start a network daemon that is responsible for keeping the TCP connection open, and thusly should still be keeping the connection alive after a message receipt. But, let me know if I am misunderstanding the workings, of course.
Thanks to whoever took the time to read this,
Cheers,
NJ
|
|
| |
Goto Forum:
Current Time: Thu Mar 23 21:57:46 GMT 2023
Powered by FUDForum. Page generated in 0.01980 seconds
|