mosquitto-1.4.9在Linux上的编译
http://mosquitto.org/download/
一、 编译依赖
1. C-ARES
是一个异步DNS请求方面的库
./configure--prefix=/usr
make
makeinstall
2. Lib UUID
sudoapt-get install uuid-dev
3. XLS
xsl:import: unable to load
sudoapt-get install docbook-xsl
4. 4.libwebsocket
mkdirbuild
cdbuild
cmake..
make
makeinstall
二、 编译
修改config.mk里,WITH_WEBSOCKETS:=yes
make
makeinstall
三、 配置
cp/etc/mosquitto/mosquitto.conf.example mosquitto.conf
添加websockets的监听端口
port1883
listener8080
protocolwebsockets
则1883和8080端口同时启用。
四、 启动服务
mosquitto–v -c /etc/mosquitto/mosquitto.conf
-d 以后台伺服方式启动
五、 测试
mosquitto_sub:error while loading shared libraries: libmosquitto.so.1: cannot open sharedobject file: No such file or directory
重新执行ldconfig
mosquitto_pub -t location -h localhost -m"12345"
mosquitto_sub -t location
订阅系统消息:
mosquitto_sub -t \$SYS/# -h localhost
订阅所有消息:
mosquitto_sub -t “#” -h localhost
六、 交叉编译
(一) 编译需要依赖的openssl
./config no-asm shared--prefix=/home/liufei/mqtt/openssl
然后修改Makefile中下列变量的值:
CC = /opt/arm-2013.11/bin/arm-none-linux-gnueabi-gcc
AR = /opt/arm-2013.11/bin/arm-none-linux-gnueabi-ar
RANLIB = /opt/arm-2013.11/bin/arm-none-linux-gnueabi-ranlib
INSTALLTOP = /home/MQTT/openssl
OPENSSLDIR = /home/MQTT/openssl
然后搜索-m64,都去掉
make
make install
(二) 编译mosquitto-1.4.9客户端
修改config.mk
WITH_SRV:=no
WITH_UUID:=no
WITH_WEBSOCKETS:=no
WITH_DOCS:=no
CFLAGS +=-I/home/liufei/mqtt/openssl/include
LDFLAGS += -L/home/liufei/mqtt/openssl/lib-lssl -lcrypto
make CC=/opt/arm-2013.11/bin/arm-none-linux-gnueabi-gccCXX=/opt/arm-2013.11/bin/arm-none-linux-gnueabi-g++
七、 JS客户端
http://www.eclipse.org/paho/clients/js/
八、 各种版本和语言的mqtt库
https://github.com/mqtt/mqtt.github.io/wiki/libraries
mqtt推送消息——发送端使用.net:http://biancheng.dnbcw.info/net/465216.html
在windows上的安装运行
下载地址:
http://mosquitto.org/download/
需要openssl和pthead库:
https://slproweb.com/download/Win32OpenSSL_Light-1_0_2h.exe
pthreads-w32-2-9-1-release.zip(Pre-built.2\dll\x86\*)
emqtt服务
这个和mosquitto相比,较为完善,尤其是安全控制,如全局消息的订阅权限等,在mosquitto中,我暂时没有找到禁止订阅全部消息的方法,这个在实际应用中,对于安全相当重要。不然任何一个接入mqtt网络中的客户端都有权订阅全部消息,就相当于任何消息对于它来说都是可见的。Emqtt中默认是只允许在mqtt服务本机上订阅全部消息。