Windows環境下搭建MosQuitto服務器
阿新 • • 發佈:2019-01-20
環境 file png 模塊 get 文件測試 pos message .org
,另一種是直接下載官網提供的編譯好的
Windows環境下搭建MosQuitto服務器
2018年04月16日 22:00:01 wistronpj 閱讀數:1185 摘自:https://blog.csdn.net/pjlxm/article/details/79967322Windows環境下搭建MosQuitto服務器
原創 2016年12月06日 19:51:55MosQuitto服務器的搭建
官網地址
Windows環境下搭建服務器
參考文章: [移動] Mosquitto簡要教程(安裝/使用/測試)
下載、安裝MosQuitto服務器
首先在DownLoad界面,下載服務器源碼,一種是根據源碼下載,然後在本地通過Cygwin編譯Source
Binary Installation
。
筆者在采用第一種源碼安裝的時候,遇到了一個問題,安裝openssl後暫時仍未解決。
於是本文采用的是第二種方式,根據readme的提示,如果缺少libeay32.dll,ssleay32.dll,pthreadVC2.dll
的話,可以根據提示安裝對應的環境也可以直接下載相應的dll文件,筆者直接下載的單獨的dll文件測試成功。
- Dependencies - win32
- --------------------
- * OpenSSL
-
Link: http://slproweb.com/products/Win32OpenSSL.html
- Install "Win32 OpenSSL <version>"
- Required DLLs: libeay32.dll ssleay32.dll
- * pthreads
- Link: ftp://sourceware.org/pub/pthreads-win32
- Install "pthreads-w32-<version>-release.zip
- Required DLLs: pthreadVC2.dll
-
Please ensure that the required DLLs are on the system path, or are in the same directory as
- the mosquitto executable.
- Dependencies - Cygwin
- ---------------------
- * OpenSSL
- Link: http://slproweb.com/products/Win32OpenSSL.html
- Install "Win32 OpenSSL <version>"
- * pthreads
- Link: ftp://sourceware.org/pub/pthreads-win32
- Install "pthreads-w32-<version>-release.zip
- * Cygwin
- Link: https://www.cygwin.com/setup-x86.exe
- Required packages: libgcc1, openssl, zlib0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
安裝完成後如下圖所示:
其中幾個主要的作用如下:
模塊 | 功能 |
---|---|
mosquitto.conf | mosquitto服務器的配置文件 |
mosquitto | 用來開啟broker |
mosquitto_passwd | 用來設置用戶的賬號與密碼 |
mosquitto_pub | 用來發布消息 |
mosquitto_sub | 用來訂閱消息 |
pwfile.example | 通過mosquitto_passwd來存儲用戶的賬號密碼的文件 |
測試服務器
創建Broker、訂閱、發布消息可以通過命令行來進行,我們首先測試一下服務器是否可以正常運行:
- 開啟服務器
mosquitto -c mosquitto.conf
,通過命令行運行,如果沒有出現其他提示表示成功,此時我們可以自己發布、訂閱消息來進行下面的測試了。
- 訂閱與發布
- 通過
mosquitto_sub -v -t {topic}
來訂閱Topic,其中{topic}
就是訂閱的主題。 - 通過
mosquitto_pub -t {topic} -m {message}
來發布消息,其中{topic}
即發布的主題,{message}
即要發布的信息。 - 演示Gif:可以看到我們測試中,接收
topic
的主題,當發布之後成功的接收到了訂閱的主題。
- 通過
補充功能
-
設置用戶的賬號與密碼:
mosquitto_passwd [ -c | -D ] passwordfile username
-
-c
表示創建一個新的用戶並寫入到一個文件中。 -
創建成功之後,我們打開該文件,可以看到裏面保存了我們剛剛創建的用戶的賬號,而密碼則幫我們進行了加密。
-
創建之後,不要忘記修改
mosquitto.conf
中的password_file pwfile.example
, 將其修改成我們剛剛創建的passwordfile使其生效。
-
總結與預告
本次成功的在Windows環境下部署了Mosquitto服務器,下篇文章將演示如果在手機客戶端上接受到推送的信息。
Windows環境下搭建MosQuitto服務器