wufawei


基于MQTT实现Android消息推送(Push) 中介绍了android客户端使用MQTT的示例代码  AndroidPushNotificationsDemo


有一个Mosquitto,实现Server/broker的网站,可以用来作为测试网站,使用这个网站发送消息的示例代码如下。


#!/usr/bin/env python
#
coding=utf-8


import mosquitto
import os
import time

broker = "test.mosquitto.org"
port = 1883

mypid = os.getpid()
client_uniq = "pubclient_"+str(mypid)
mqttc = mosquitto.Mosquitto(client_uniq)

#connect to broker
mqttc.connect(broker, port, 60, True)

#remain connected and publish
while mqttc.loop() == 0:
msg = "test message "+time.ctime()
mqttc.publish("topic/deviceId", msg)
print "message published"
time.sleep(1)
pass

分类:

技术点:

相关文章:

  • 2021-11-26
  • 2021-12-04
  • 2022-01-12
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2021-06-30
猜你喜欢
  • 2021-12-04
  • 2021-12-16
  • 2021-08-09
  • 2022-12-23
  • 2021-06-11
  • 2021-07-03
相关资源
相似解决方案