mqtt之初步探索

 

mosquitto-1.4.9Linux上的编译

http://mosquitto.org/download/

 

一、   编译依赖

1.     C-ARES

http://c-ares.haxx.se/

是一个异步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

18838080端口同时启用。

四、   启动服务

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推送消息——发送端使用.nethttp://biancheng.dnbcw.info/net/465216.html

 

 

 

windows上的安装运行

下载地址:

 

http://mosquitto.org/download/

 

 

需要opensslpthead库:

https://slproweb.com/download/Win32OpenSSL_Light-1_0_2h.exe

 

pthreads-w32-2-9-1-release.zipPre-built.2\dll\x86\*

emqtt服务

这个和mosquitto相比,较为完善,尤其是安全控制,如全局消息的订阅权限等,在mosquitto中,我暂时没有找到禁止订阅全部消息的方法,这个在实际应用中,对于安全相当重要。不然任何一个接入mqtt网络中的客户端都有权订阅全部消息,就相当于任何消息对于它来说都是可见的。Emqtt中默认是只允许在mqtt服务本机上订阅全部消息。

 

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值