Mosquitto Installation of MQTT learning

Source: Internet
Author: User
Tags sha1 socket socket error

Do the development of MQTT and record some learning processes.

Installation includes:

1, RPM Installation

2. Source code Installation


(i) Installation with RPM

Installation Environment Centos6.4

Download the Mosquitto RPM installation package from the link below: Click the Open link (http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/i686/)


To run the Install command:

[Root@localhost xxx]# rpm-i mosquitto-1.3.1-3.1.i686.rpm 
warning:mosquitto-1.3.1-3.1.i686.rpm:header V3 DSA/ SHA1 Signature, Key ID 49e1d0b1:nokey

Hint has warning, checked, this warning can be ignored. The method is to install the following instructions:


[Root@localhost xxx]# rpm-uhv mosquitto-1.3.1-3.1.i686.rpm 
warning:mosquitto-1.3.1-3.1.i686.rpm:header V3 DSA/ SHA1 Signature, key ID 49e1d0b1:nokey
Preparing ...                ########################################### [100%] Package
	mosquitto-1.3.1-3.1.i686 is already installed

As shown above, the installation is successful.

Here's a look at the service.

[Root@localhost/]# mosquitto
mosquitto         mosquitto_passwd  

At the command line input: Mosquitto, press two times tab, the following two instructions appear. Indicates that the Mosquitto has been installed successfully. To start the Mosquitto service, you only need to enter the mosquitto instruction. As follows:

[Root@localhost/]# mosquitto
1396234681:mosquitto version 1.3.1 (build date 2014-03-25 00:14:12+0000) starting
1396234681:using Default CONFIG.
1396234681:opening IPv4 Listen socket on port 1883.
1396234681:opening IPv6 Listen socket on port 1883.
1396234750:new connection from 192.168.139.80 on port 1883.
1396234750:new client connected from 192.168.139.80 as QYLMQTT (c1, K60).

The last line of QYLMQTT is the client ID I developed on the Windows side, indicating that I have connected to the MQTT server from the client.


There are no Mosquitto published and subscribed clients, only servers. Install the Mosquitto client below.

1. Download the Mosquitto client from the address above to download the RPM package.

The main ones are the following RPM packages:

libmosquitto1-1.3.1-3.1.i686.rpm   
mosquitto-clients-1.3.1-3.1.i686.rpm  

Note that there are several C + + devel, do not download the wrong, and as if C + + Devel also need to install libmosquitto1-1.3.1-3.1.i686.rpm

2. Install the two RPM packages as described above in the installation of the RPM package

3. After successful installation, enter Mosquitto,tab two times at the command line, and the following commands are displayed:

[Root@localhost ~]# mosquitto
mosquitto         mosquitto_passwd  mosquitto_pub     


Visible, the client is already installed.


4. Operation

To open the server:

[Root@localhost ~]# mosquitto
1396235903:mosquitto version 1.3.1 (build date 2014-03-25 00:14:12+0000) starting
1396235903:using Default CONFIG.
1396235903:opening IPv4 Listen socket on port 1883.
1396235903:opening IPv6 Listen socket on port 1883.
1396235917:new connection from:: 1 on port 1883.
1396235917:new client connected from:: 1 as Mosqsub/1915-localhost. (C1, k60).
1396235953:new connection from:: 1 on port 1883.
1396235953:new client connected from:: 1 as Mosqpub/2397-localhost. (C1, K60).


Subscription:

[Root@localhost ~]# mosquitto_sub-t test-d
client mosqsub/1915-localhost. Sending CONNECT
client mosqsub/1915 -localhost. Received CONNACK
client mosqsub/1915-localhost. Sending SUBSCRIBE (mid:1, Topic:test, qos:0)
client Mosqsub/19 15-localhost. Received SUBACK
subscribed (mid:1): 0
Client mosqsub/1915-localhost. Received PUBLISH (D0, q0, R0, M0, ' test ', ... . (bytes))
Hello World
Client mosqsub/1915-localhost sending PINGREQ
client mosqsub/1915-localhost. Received PINGRESP
Client mosqsub/1915-localhost. Sending PINGREQ
Client Mosqsub/1915-localhost. Received PINGRESP
client mosqsub/1915-localhost. Sending PINGREQ
client mosqsub/1915-localhost. Received Pingresp
client mosqsub/1915-localhost. Sending PINGREQ
client mosqsub/1915-localhost. Received PINGRESP


Release:

[Root@localhost ~]# mosquitto_pub-t test-m "Hello World"
-D Client mosqpub/2397-localhost. Sending CONNECT
Clie NT Mosqpub/2397-localhost. Received CONNACK
Client mosqpub/2397-localhost sending PUBLISH (D0, Q0, R0, M1, ' Test ', ... (bytes))
Client Mosqpub/2397-localhost. Sending DISCONNECT


The "Hello World" displayed in the subscription column is the published message.


The following is your own test VC + + client to publish the message of the routine, first note, go back to discuss with VC + + development Mosquitto Client method.

Server:

[Root@localhost ~]# mosquitto
1396245090:mosquitto version 1.3.1 (build date 2014-03-25 00:14:12+0000) starting
1396245090:using Default CONFIG.
1396245090:opening IPv4 Listen socket on port 1883.
1396245090:opening IPv6 Listen socket on port 1883.
1396245096:new connection from:: 1 on port 1883.
1396245096:new client connected from:: 1 as Mosqsub/19451-localhost (c1, k60).
1396245108:new connection from 192.168.139.80 on port 1883.
1396245108:new client connected from 192.168.139.80 as QYLMQTT (c1, k60).
1396245110:socket error on client qylmqtt, disconnecting.
1396245189:new connection from 192.168.139.80 on port 1883.
1396245189:new client connected from 192.168.139.80 as QYLMQTT (c1, k60).
1396245190:socket error on client qylmqtt, disconnecting.


Subscription:

[Root@localhost ~]# mosquitto_sub-t test-d
client mosqsub/19451-localhost sending CONNECT
Client mosqsub/ 19451-localhost received CONNACK
Client mosqsub/19451-localhost sending SUBSCRIBE (mid:1, Topic:test, qos:0)
C Lient Mosqsub/19451-localhost received SUBACK
subscribed (mid:1): 0
Client Mosqsub/19451-localhost received PUBLISH (D0, q0, R0, M0, ' test ', ...) (4 bytes))
Hell
client Mosqsub/19451-localhost sending PINGREQ
client Mosqsub/19451-localhost received
PINGRESP Client Mosqsub/19451-localhost received PUBLISH (D0, q0, R0, M0, ' test ', ... (bytes))
Hello World, the a message from VC + + client.

The receiver receives only "Hell" for the first time, presumably because of an error in calculating the length of the payload when it is sent. The second acceptance is normal.


(ii) Source code installation

In fact, from last year to the beginning of the first time I used to install the Mosquitto, but this morning installed the latest version of Mosquitto, found that the source code is not installed, and then in order to test my VC + + client as soon as possible to select the RPM installation. Afternoon focused on solving the problem of source code installation.


1. System: centos6.4

2. Download Source: Download Address (http://mosquitto.org/download/)

I downloaded the latest update of the mosquitto-1.3.1.tar.gz


3. Decompression

Tar zxvf mosquitto-1.3.tar.gz


4, temporarily do not use SSL, so when the installation I turned off the SSL

[Root@localhost mosquitto-1.3]# make With_tls=no set-e; For D in Lib client src; Do Make-c ${d}; Done Make[1]: Entering directory '/qyl/mosquitto-1.3/lib ' Cc-wall-ggdb-o2-i.-I.. -I.. /lib-fpic-dwith_threading-dwith_srv-c mosquitto.c-o mosquitto.o in file included from Mosquitto.c:46:mosquitto_inter Nal.h:51:20:error:ares.h:no such file or directory in file included from Mosquitto.c:46:mosquitto_internal.h:238:erro R:expected specifier-qualifier-list before?
Res_channel? Mosquitto.c:in function?
Osquitto_loop?. Mosquitto.c:834:error:?. Truct Mosquitto? Has no member named?.
Chan? Mosquitto.c:837:warning:implicit declaration of function?.
Res_fds? Mosquitto.c:837:error:?. Truct Mosquitto? Has no member named?.
Chan? Mosquitto.c:917:error:?. Truct Mosquitto? Has no member named?.
Chan? Mosquitto.c:918:warning:implicit declaration of function?.
Res_process? Mosquitto.c:918:error:?. Truct Mosquitto? Has no member named?.
Chan? MAKE[1]: * * [MOSQUITTO.O] Error 1 mAKE[1]: Leaving directory '/qyl/mosquitto-1.3/lib ' make: * * * [Mosquitto] Error 2 

Find Ares.h in Lib/mosquitto_internal.h and find that this header file is controlled by the macro definition with_srv.

Do not know what SRV support is, but check the Mosquitto update log, found that SRV support was added on March 16 this year, I said last year source installation has been no problem, this year how to die.

Workaround, turn off SRV support in the CONFIG.MK configuration file. The following figure:

# Build with SRV lookup support.
With_srv:=no

Perform make again to install it successfully.


5. Verification

Enter Mosquitto,tab two times on the command line:

[Root@localhost mosquitto-1.3]# mosquitto
mosquitto         mosquitto_passwd  mosquitto_pub     

The Mosquitto server and client are installed successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.