分享

搭建Android MQTT推送平台

 心不留意外尘 2016-07-15

http://blog.csdn.net/lee4755026/article/details/9699713

2013

最近研究了一下Android推送,在网上搜到了很多种方式,觉得IBM的MQTT协议这种方式还是挺不错的。

下面介绍一下搭建过程:

需要准备的工具如下:

(1)、下载Mosquitto(MQTT的代理,也可以用IBM的ISMB)
http:///download/

我下载的是mosquitto-1.1.2-install-win32.exe,根据自己的需要下载,不安装这个推送不了消息。
(2)、下载AndroidPushNotificationsDemo
https://github.com/tokudu/Androi ... /archive/master.zip

(3)、下载PhpMQTTClient
https://github.com/tokudu/PhpMQTTClient/archive/master.zip

将PHPMQTTClient部署到PHP服务器上,运行,打开mosquitto安装目录的mosquitto.exe

 

将以下AndroidPushNotificationsDemo的代码根据自己的情况修改。

  1. public class PushService extends Service  
  2. {  
  3.     // this is the log tag  
  4.     public static final String      TAG = "DemoPushService";  
  5.   
  6.     // the IP address, where your MQTT broker is running.  
  7. //修改成自己的服务器地址  
  1.     private static final String     MQTT_HOST =   
  2. //          "209.124.50.174"  
  3. //          "192.168.12.19"   
  4.             "10.0.2.2"   
  5.             ;  
  6.     // the port at which the broker is running.   
  7.     private static int              MQTT_BROKER_PORT_NUM      = 1883;  
  8.     // Let's not use the MQTT persistence.  
  9.     private static MqttPersistence  MQTT_PERSISTENCE          = null;  

 

输入Device target ID ,内容,点击按钮,OK!



PS:

原来其实是不需要那个PHP的,直接用mosquitto_pub.exe就可以测试了,运行客户端程序,在命令窗口中使用Mosquitto_pub.exe -q [Qos级别] -t [主题] -m [发布的内容] 进行测试。这个android客户端例子中订阅的topic是“tokudu/你的deviceID”。


一些别的资料:

http://www.cnblogs.com/yjl49/archive/2012/05/17/2506819.html



 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多