基于MQTT实现Android消息推送(Push)(2)
16lz
2021-12-04
在基于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
更多相关文章
- Android(安卓)Studio之编译t提示Invoke-customs are only suppor
- Android(安卓)USB/MTP相关实现
- Android(安卓)Selector和Shape的使用方法
- android 使用TextView/EditText应该注意的地方
- Android--使用include调用布局
- android:shape的使用2
- android:required="false"
- ListView之setEmptyView的问题
- Android如何代码混淆