Module 4
Module 4
• HTTP
• WebSocket
• Real time clients
• MQTT
• MQTT – SN
• CoAP
• STOMP
• AMQP
• Comparison of protocols
1
IoT Application layer protocol
• It is a protocols are interface between the IoT device and network
with which it will communicate.
• The function of application layer protocols are handling data formats,
presentation and server as bridge between IoT device and network
• The type of protocol used will be depending of on following factors :
1) Data latency :- How fast the data is transported.
2) Reliability :- How redundant our device communication is
3) Bandwidth :- What is volume of data to be stored.
4) Transport :- What type of transport protocol is used.
2
HTTP (Hyper Text Transfer Protocol) :-
2) Media independent:- Both client & server know how to handle the data
content. So it is said to be media independent.
3) Stateless :- The client & server know each other only during current request.
Hence HTTP is called as stateless protocol. (Do not hold the information in
other requests).
4
❖ Messages :-
A request line
Headers
A blank line
Body
[Present only in some messages]
5
2) Response :- The server replies to the request message by sending
response message. This consists of –
Status line
Headers
A blank line
Body
[only in some messages]
6
❖ URL [Uniform Resource Locater] :-
A client that wants to access the document in Internet needs an address & to
facilitate the access of documents, the HTTP uses the concept of URL.
• URL is a standard way of specifying any kind of information on internet (www).
• The URL defines 4 parts :
1) Method: The method of protocol is used to retrieve the document from a server
(Ex: HTTP)
2) Host: The host is computer where the information stored and computer is given
an alias name. Web pages are mostly stored in the computers which are given an
alias name called as “www“. This field is not mandatory.
7
3) Port : URL also contain port number of server. But which is optional
field. Separated between host and port with colon.
4) Path : It is the path name of file where the information is stored.
Path itself contains slashes that separate the directories from
subdirectories and files.
Disadvantages :-
a) Requires high powers to establish communication.
b) Less secure.
c) Not optimized for cellular phone.
d) Cannot be available for other clients when one client is receiving
data from that server.
8
WebSocket
• WebSocket is a bidirectional, a full duplex protocol, that is used in the client
server communication.
• It is a stateful protocol, which means the connection between client and server
will keep alive until it is terminated by either client or server.
• Format :
• ws:// www.google.com (on)
• wss:// www.google.com
• For example, let's take client server communication, there is a client which is web
browser and a server, whenever we Initiate the connection between client and
server, they both made the handshaking and decide to create a new connection
and will be alive until terminated by any of them.
9
• When the connection is established and alive, the communication
takes place using the same connection channel until it is terminated.
Request
Response Server
Client
WebSocket
10
❖Applications :-
1) Real time web application :
This uses WebSocket to show the data at the client end all the time sent by
the server. In WebSocket, data is continuously being sent in the same
connection which is already open. Hence WebSocket is faster & improves the
application performance.
Ex:- In trading website or bitcoin trading, for displaying the price fluctuation
and movement of data is continuously pushed by backend server to the client
end by WebSocket channel.
2) Gaming application :
In gaming application also data is continuously received by the server.
without establishing new connection UI gets automatically refreshed
11
3) Chat application :
Chat applications use WebSocket to establish the connection only for
exchange, publishing and broadcasting the messages among the subscribers.
Disadvantages :-
Only for real – time applications, it can be used. Can not get old data.
12
Message Queue Telemetry Transport (MQTT)
• It is a machine to machine (M2M) or IoT connectivity protocol.
• It is a TCP based protocol relying on the publish-Subscribe model.
• This communication protocol is suitable for transmitting data between
resource-constrained devices having low bandwidth & low power requirements
• This will establish communication between the multiple devices using Publish
Subscribe Model.
• All the devices will interact with each other via third party called Broker, but not
directly.
• The broker receives the messages of different topics sent by the client and filters
them.
• After that they are sent to the respective clients who have subscribed to that topic
13
• Hence client that has subscribed to a Specific topic receives all the messages
published on that topic.
Receives messages
Publi
she Filters , distribute ri b er
s c
Clien r Sub ent
t Pu h Cli
bli s
sh bli
Pu r
r i be
b sc
Su
Publish Publish Subscriber
Publisher Broker
Client Client
Subscriber
ish Pub
b l lish
Pu Su
bsc Sub
rib scrib
b li s her er Clie er
Pu t nt
Clien
1) Easy Scalability :
• One to many, many to many Communication is possible using this model
• Also, client can publish and also subscribe at the same time due to this
two-way communication, MQTT protocol is considered to be bi-directional
protocol.
15
MQTT-SN (MQTT for sensor networks)
16
4) MQTT-SN forwards
✔ used when clients Cannot communicate with gateway
✔ forwards messages to gateway through internet from clients.
✔ Also receives messages from gateways to the clients unchanged.
MQTT MQTT- SN
Packets Packets
Client Broker Client
Gateway
Publisher Subscriber
Forwards
17
Constrained Application Protocol (COMP):
• It is also an applications layer protocol for machine to machine (M2M) applications.
• This protocol is a client-server-based protocol uses request-response model.
• Like HTTP, COAP is a web transfer protocol and uses UDP as Transport protocol.
• CoAP can easily interface with HTTP
• The CoAP packets can be shared between different client nodes which commanded
by COAP server.
• This model will be one-one Communication.
• The CoAP server will interpret it, extract the payload and decide what to do
depending on its logic. The server does not necessarily hav to acknowledge the
request.
18
Client
Server
19
Streaming Text Oriented Message protocol
(STOMP) :
• STOMP is an application layer protocol, which provides an
interoperable wire format so that STOMP clients can communicate
with message any STOMP broker.
• This provides easy and widespread. messaging interoperability among
many languages. platforms and broken.
• The main disadvantage of STOMP is it may be hard to implement the
server side but is very easy to write client to connect It can also get
interfaced with HTTP
20
Advanced Message Queuing Protocol (AMQP) :
• It is open standard application layar protocol.
• It also uses publish subscribe architectures.
Subscribers
Exchange Queues
Client
Publisher E
Routing
Broker Client
2) Exchange : This is the place where publishers deliver messages. The messages
contain routing keys which are used by exchange module, in order to route
them.
6) Routing Key : It is a message attribute. The exchange might look at this key
when deciding how to route the message to queues.
22
Comparison of application layer protocols :-
Criteria HTTP MQTT AMQP CoAP
Year 1997 1999 2003 2010
Message size Large & Small & Negotiable and Small & Undefined
Undefined Undefined Undefined
23
Semantics / Get, Post, Head, Connect, Consume, Deliver, Get, Post, Put,
Methods Put, Patch, Disconnected, Publish, Get, Delete
Options, Publish, Subscribe, Select, Ask,
Connect, Delete Unsubscribe, Close Delete, Recover,
Reject, Open,
Close
Security TLS / SASL TLS / SSL TLS / SSL, IPSec, DTLS, IPSec
SASL
Encoding format Text Binary Binary Binary
24