Search code examples
tcpmqtt

What are advantages of MQTT over TCP/IP? Since MQTT is based on TCP, Why don't we use TCP/IP instead of it?


I am studding the MQTT & TCP/IP protocol.

Since i'm able to know that, MQTT is based on the TCP so as the TCP/IP & we refer MQTT though we have the TCP/IP Protocol.

Why don't we use TCP/IP instead of MQTT?

Is there any advantages of MQTT that makes it better solution than the TCP/IP protocol?

Which is more reliable & required less no of data packet to form a communication?

(Note : TCP/IP in the sense forming a network between 2 devices using normal TCP/IP protocol as in GSM modems "connect > transfer data > disconnect")


Solution

  • Is there any advantages of MQTT that makes it better solution than the TCP/IP protocol?

    Yes, it offers things TCP doesn't offer, namely an application layer protocol. Other examples of such protocols are FTP, HTTP, SMTP.

    You're asking the wrong question. IP makes sure you can send data to another machine, TCP makes sure this data is received in-order and acknowledged, and application-level protocols make sure you can make sense of the data you receive.

    Without an application level protocol, you have no meaningful communication. Where each sockets programming example begins with "WriteLine" and "ReadLine" text message exchanges, that in itself is (albeit a very rudimentary) application level protocol, namely "client and server exchange text messages ending in a newline".

    So, no, you cannot use TCP/IP without an application level protocol, because as soon as you start writing a program sending and/or receiving data, you have at that moment defined an application level protocol.

    With its own problems. And that's why you shouldn't invent your own protocol, but use existing ones. Pick the one that suits your needs. Do you need to publish or subscribe messages to some broker, use MQTT.

    Unless you know very well what you're doing, don't invent your own.