mqtt的开源实现mosquitto的交叉编译与使用

mqtt协议是最近比较流行的即时推送的协议
到 http://mosquitto.org/download/ 下载源码
或者跟我一样我直接下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版本的,能支持更多的并发连接
https://bitbucket.org/wowsoso/mosquitto/src/e3a9efbbb06b6820057ecc40b91df79f0fabce93/src/loop.c?at=default

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(3817) | 评论(0) | 转发(0) |
0

上一篇:gsoap:import: Cannot open file "stlvector.h" for reading

下一篇:交叉编译faad

给主人留下些什么吧!~~
评论热议

猜你喜欢

转载自blog.csdn.net/zmlovelx/article/details/80263014