Basic Comparison of XMPP, MQTT, HTTP, and CoAP Protocols

1. First, let’s take a look at the comparison of the four major protocols based on relevant foreign professional data:

Protocol CoAP XMPP RESTful HTTP MQTT

Transport UDP TCP TCP TCP
Messaging Request/Response Publish/Subscribe Request/Response Request/Response Publish/Subscribe Request/Response
2G, 3G, 4G Suitability (1000s nodes) Excellent Excellent Excellent Excellent
LLN Suitability (1000s nodes) Excellent Fair Fair Fair
Compute Resources 10Ks RAM/Flash 10Ks RAM/Flash 10Ks RAM/Flash 10Ks RAM/Flash
Success Stories Utility Field Area Networks Remote management of consumer white goods Smart Energy Profile 2 (premise energy management/home services) Extending enterprise messaging into IoT application

XML parsing can be quite painful for embedded devices, so when developing on embedded devices, it is best not to choose XML-based protocols.

2. Basic Introduction to the Four Major Protocols:

IoT Protocol XMPP

XMPP is a protocol based on a subset of the standard generalized markup language XML, inheriting the flexible development capability in an XML environment. Therefore, applications based on XMPP have strong scalability. The extended XMPP can handle user needs by sending extended messages and establish applications such as content publishing systems and address-based services at the top of XMPP. Moreover, XMPP includes software protocols for server-side communication, making it easier for developers to create client applications or add functionality to an already configured XMPP protocol system.

IoT Protocol MQTT

MQTT (Message Queuing Telemetry Transport) is an instant messaging protocol developed by IBM that could become an important part of the Internet of Things. The protocol supports all platforms and can connect almost all networked items with external connections, used as a communication protocol for sensors and actuators (e.g., connecting homes via Twitter).

IoT Protocol CoAP

CoAP stands for Constrained Application Protocol. In recent years, experts have predicted that more devices will connect to each other, far exceeding the number of humans. Against this backdrop, IoT and M2M technologies have emerged. While connecting to the Internet may seem convenient and easy for humans, it is extremely challenging for small devices. In a world dominated by PCs, information exchange is achieved through TCP and application layer protocols like HTTP. However, for small devices, implementing TCP and HTTP protocols is clearly an excessive requirement. To allow small devices to connect to the Internet, the CoAP protocol was designed. CoAP is an application layer protocol that runs over UDP instead of TCP like HTTP. CoAP is very compact, with the smallest data packet being only 4 bytes.

IoT Protocol RESTful HTTP

REST refers to a set of architectural constraints and principles. Applications or designs that satisfy these constraints and principles are RESTful.

The most important REST principle for web applications is that interactions between clients and servers are stateless between requests. Each request from client to server must contain the information necessary to understand the request. If the server restarts at any point between requests, the client will not be notified. Additionally, stateless requests can be answered by any available server, which is very suitable for cloud computing environments. Clients can cache data to improve performance.

3. From existing mobile (Android) push notification solutions, we can also see the pros and cons of MQTT and XMPP protocols.

Solution 1: Use GCM service (Google Cloud Messaging) Overview: Cloud messaging service launched by Google, the second generation of G2DM. Advantages: Service provided by Google, native, simple, no need to implement and deploy server. Disadvantages: Android version restriction (must be greater than 2.2), the service is not stable in China, requires users to bind a Google account, restricted by Google. Solution 2: Use XMPP protocol (Openfire + Spark + Smack) Overview: A communication protocol based on XML, originally Jabber, now standardized by IETF. Advantages: Mature protocol, powerful, strong scalability, currently mainly used in many chat systems, with open-source Java version development examples like androidpn. Disadvantages: Protocol is relatively complex, redundant (based on XML), consumes traffic and power, high hardware deployment costs. Solution 3: Use MQTT protocol (more information: http://mqtt.org/) Overview: A lightweight, broker-based “publish/subscribe” message transmission protocol. Advantages: Simple, compact protocol, strong scalability, saves traffic and power, already applied in enterprise fields (reference: http://mqtt.org/software), and has a C++ version of the server component rsmb. Disadvantages: Not mature enough, implementation is complex, server component rsmb is not open-source, high hardware deployment costs. Solution 4: Use HTTP polling method Overview: Regularly fetch the latest messages from the HTTP server interface (Web Service API). Advantages: Simple implementation, strong controllability, low hardware deployment costs. Disadvantages: Poor real-time performance.

Research and comparison of the pros and cons of each solution recommends using the MQTT protocol solution primarily because: MQTT is the fastest, most traffic-efficient (fixed header length is only 2 bytes), and very easy to expand, suitable for secondary development.

In summary:

If we conduct a PK on the above results, I believe the final result is MQTT vs CoAP. HTTP is too heavy and inflexible for embedded devices, and XMPP is even less suitable, with CoAP being the only one comparable to MQTT – a protocol still in draft stage.

Source: http://www.iteye.com

Basic Comparison of XMPP, MQTT, HTTP, and CoAP Protocols

Leave a Comment