在基于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(安卓)Studio之编译t提示Invoke-customs are only suppor
  2. Android(安卓)USB/MTP相关实现
  3. Android(安卓)Selector和Shape的使用方法
  4. android 使用TextView/EditText应该注意的地方
  5. Android--使用include调用布局
  6. android:shape的使用2
  7. android:required="false"
  8. ListView之setEmptyView的问题
  9. Android如何代码混淆

随机推荐

  1. Android动画效果translate、scale、alpha
  2. android 自动获取时间,网络提供的值
  3. Android实现简易记事本
  4. Android(安卓)Activity切换动画详解及实
  5. android log
  6. Android中文API(146) —— Display
  7. 实战android菜单项之XML加载菜单与动态菜
  8. Android(安卓)Button 上添加图片
  9. android 城市列表
  10. Android(安卓)Studio3.4.2配置NDK