In the world of the Internet of Things, a typical network architecture is as follows: first, terminal devices or sensors collect signals or information. For devices that cannot connect to the internet or intranet, the sensors send the detected information to a gateway, which then sends the information to the server. Some devices, like smartphones, come with built-in network access capabilities and can connect directly to the server. The specific network architecture is shown in the figure below.
Sometimes, to reduce the load on the server, we can choose some lightweight communication protocols, such as MQTT, instead of HTTP. So why choose MQTT over HTTP? Because the header of the HTTP protocol is relatively large, and every time data is sent, a data packet must be sent to connect/disconnect from TCP. Therefore, the more data sent, the larger the total communication volume.
In contrast, the header of MQTT is smaller, and it can send and receive data while maintaining the TCP connection, which means it can suppress the total communication volume better than HTTP.
Additionally, when using MQTT, it is important to maintain the MQTT TCP connection while sending and receiving data. Since MQTT reduces communication volume by maintaining the TCP connection, if the connection is disconnected every time data is communicated, MQTT will behave like HTTP, executing connection and disconnection processes every time data is sent, which will actually increase the communication volume.