Ted

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


基于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
posted on 2012-03-08 23:53  wufawei  阅读(1359)  评论(0编辑  收藏  举报