Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4463114
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2016-04-08 14:37:34

mqtt协议是最近比较流行的即时推送的协议
到 下载源码
或者跟我一样我直接下git
$ git clone git://git.eclipse.org/gitroot/mosquitto/org.eclipse.mosquitto.git
$ cd  org.eclipse.mosquitto/
编译pc平台的
$ make WITH_SRV=no
运行
$ cp src/mosquitto mosquitto_pc
$ cp client/mosquitto_pub mosquitto_pub_pc
$ sudo make install
运行服务器
$ mosquitto_pc -v
pc ip是 192.168.0.108

编译arm平台的
make clean
make WITH_SRV=no CC=arm-linux-gcc CXX=arm-linux-g++
需要
./lib/libmosquitto.so.1
./client/mosquitto_sub拷贝到开发板上
(这种方式编译还需要libssl, libcrypto库,请自行拷贝)

如果要指定ssl的库位置
make WITH_SRV=no CC=arm-linux-gcc CXX=arm-linux-g++ CFLAGS="-I/thirdparty/include/ -L/thirdparty/lib" LDFLAGS="-L/thirdparty/lib -lssl -lcrypto"


在开发板上运行,订阅hello
mosquitto_sub -v -t hello -h  192.168.0.108

pc 机中推送
mosquitto_pub -t hello -h 192.168.0.108 -m "world"
【-h】指定MQTT代理服务器主机,指向PC机IP地址

开发板上会收到会打印:hello world

mosquitto用的是poll, 有一种epoll版本的,能支持更多的并发连接


阅读(15316) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~