MQTT Push Practices

Source: Internet
Author: User

Recent company development projects, using the push technology, here does not analyze the pros and cons of various push technology, online content a lot, by looking at other people's comparative data and practice, finally chose the MQTT this push protocol.

Since Mqtt is a protocol, it is natural to have its implementation, the relevant client and server-side implementations can be found at this URL: https://github.com/mqtt/mqtt.github.io/wiki/software?id=software , here server-side implementation I chose Mosquitto, the client is more than one choice, because the project involves Android, iOS and MTK platform and browser, so the choice of each platform client is not the same.

    1. The Android side and server side have been developed using Java, so Https://github.com/fusesource/mqtt-client is selected.
    2. iOS platform is not familiar with, colleagues made, selected: Https://github.com/wssand44/MQTT/tree/master/Client/MQTTMessenger/MQTTMessenger/MqttSDK.
    3. MTK Platform for an embedded development platform, using C voice development, so chose Https://github.com/menudoproblema/libemqtt, because C voice implementation uses the Linux socket library, so the implementation if you want to use directly, Can be run in Linux compilation, and we also need to target the MTK platform socket features to be ported, and finally to use.
    4. The browser uses websocket, so the http://www.eclipse.org/paho/clients/js/this JS library was selected.

Push, the core is to establish a long connection, so there are many ways to establish a connection, can be based on TCP,TLS,WB and other to establish a long connection, here is ashamed, just started not understand here, so in the client programming, just silly write: tcp://xxx.xxx.xxx : 1883, but do not know what this TCP means, fortunately, in the study of the web version of MQTT Communication, see ws://xxx.xxx.xxx:8080 only understand the meaning of this field, WS I think it should be websocket abbreviation. Since there are so many ways to establish a connection, Nature MQTT server-side implementation to support these connections, just started to think that the MQTT server-side implementation of the main work is only the management of connection and topic distribution, in fact, far from so simple, I would like to support a variety of connection methods also have a certain amount of work.

Since the beginning of the project did not involve the development of the web version, in order to quickly implement (to support TLS and other libraries to compile together), when the installation of Mosquitto, only support the TCP connection, so this time to develop the Web version to connect their own deployment of MQTT server is not, The main is the server does not support WebSocket connection mode, but this does not affect our choice of library, http://test.mosquitto.org/ Ws.html This page provides a common server address can let us test, see its JS source, he used the port is 8080, and he used the JS library is not the front said library, this nature does not matter, as long as it is based on the implementation of the MQTT protocol, in theory are able to connect to the MQTT server, just beginning I wrote 1883 no connection on ..., so the success of the connection, happy Ah, so, basically proves that the use of Mosquitto can also take care of the web version of the Mqtt push, web content real-time display in just about the corner.

As to how to make Mosquitto support WebSocket connection, this part also needs to study, later to fill in this part of the content.

About the configuration of the Mosquitto, can refer to this article, I am referring to this article successfully completed the compilation of the installation: http://blog.chinaunix.net/uid-25885064-id-3539075.html, but it is worth noting when the modification mosquitto.conf The configuration file, the user name of the bridge client inside must use the name of the currently logged-in user, and because I am the root user login, the field is configured as root to successfully start Mosquitto.

    1. # The user name of the bridge client
    2. Username Root

MQTT Push Practices

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.