在基于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

更多相关文章

  1. Android如何代码混淆
  2. android 实用代码片段整理
  3. [代码分享] 乐淘Android客户端源码
  4. 在Ubuntu上下载编译安装Android最新内核源代码
  5. Android中Timer使用示例
  6. 几个android实用网站

随机推荐

  1. android颜色值
  2. 【Android】向sdcard中写入文件
  3. Android传感器(六):光传感器
  4. Android 4.0 HttpURLConnection 下载失败
  5. Android绘制一条边为弧形的矩形
  6. Android 下载网络url文件并显示进度
  7. Android手指绘图Demo
  8. android ImagView缩放方法之一(Bitmap)
  9. android okgo post传数组
  10. [入门阅读]怎样在android中解析JSON