如何为Paho mqtt用python发送PINGREQ? [英] How do you send a PINGREQ in python for paho mqtt?

查看:617
本文介绍了如何为Paho mqtt用python发送PINGREQ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式连接到我的蚊子经纪人

I connect to my mosquitto broker with

client.connect("192.168.1.1",1883,60)

建立连接,服务器每60秒就会收到一次流量. Paho文档引用了PINGREQ/PINGACK消息,我想使用该消息来保持连接的活动状态.

to establish the connection, and the server expects traffic every 60 seconds. The paho documentation refers to a PINGREQ/PINGACK message which I would like to use to keep the connection alive.

找不到任何示例-如何在python(2.7)中做到这一点?

Can't find any examples of this - how to do this in python (2.7)?

推荐答案

简短的答案是你不

ping是由MQTT客户端网络环路处理的. .连接后,您需要启动它.有3种运行循环的方式:

The pings are handled by the MQTT Client network loop. You need to start this after connecting. There are 3 ways to run the loop:

  1. client.start_loop()这将在后台线程上启动网络循环
  2. client.loop_forever()这将在当前线程上启动网络循环,并将永远阻塞.
  3. client.loop()这将执行网络循环的一个循环,并且必须作为您自己的循环的一部分来调用.
  1. client.start_loop() This starts the network loop on a background thread
  2. client.loop_forever() This starts the network loop on the current thread and will block forever.
  3. client.loop() this executes one cycle of the network loop and must be called as part of your own loop.

这篇关于如何为Paho mqtt用python发送PINGREQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆