Open In App

Constrained Application Protocol (CoAP)

There are several protocols in the application layer of the Internet protocol suite. One such useful protocol is the CoAP or Constrained Application Protocol. This protocol has a wide range of advantages and applications in the field of the Internet of Things (IoT) and cloud computing. CoAP also has a powerful contribution in providing versatile solutions to IoT applications.
This article delves into a set of key topics and fundamental concepts in CoAP protocol along with its applications in the real world.

What is CoAP?

CoAP or Constrained Application Protocol, as the name suggests, is an application layer protocol that was introduced by the Internet Engineering Task Force in the year 2014. CoAP is basically designed for the constrained environment.



It is a web-based protocol that resembles HTTP. It is also based on the request-response model. Based on the REST-style architecture, this protocol considers the various objects in the network as resources. These resources are uniquely assigned a URI or Uniform Resource Identifier. The data from one resource to another resource is transferred in the form of CoAP message packets whose format is briefly described later.

The Client requests for some resources and in response to that, the server sends some response over which the client sends an acknowledgement. Although, some types of CoAP do not involve the receiver sending acknowledgments for the information received. This type of CoAP message is called NoN or Non Confirmable messages, whereas the messages in which the receiver sends a response to sender is known as CON or confirmable messages.



Similar to HTTP, a CoAP request is sent by a client using a method code to request an action on a URI identifiable object.
The server replies with a response code which may include a resource representation. CoAP model is essentially a client/server model enabling the client to request for service from server as needed and the server responds to client’s request.

However, CoAP messages are asynchronous since it uses UDP. The message layer interfaces with UDP layer which formats the data received into a datagram and sends it to the lower layer of the OSI or the TCP/IP model.

Methods in CoAP

CoAP is a web-based protocol. This means CoAP resembles the HTTP protocol and is capable to utilize the HTTP methods.
These methods are-

The most fundamental difference between CoAP and HTTP is that CoAP defines a new method which is not present in HTTP. This method is called Observe method.

The observe method is very similar to the GET method in addition with an observe option. This alerts the server, to send every update about the resource to the client. Therefore, upon any change in the resource, the server sends a response to the client.

These responses could either be directly sent individually or they can be piggy-backed.

Message Format of CoAP

CoAP messages are encoded in binary-format or 0/1 format. Like other message formats, CoAP message has a header and a payload section along with an optional section.

The size of CoAP header is 4 bytes or 32 bits. This size is fixed for every CoAP message. Whereas the other part of message is the optional part which includes payload and tokens of variable size ranging from 0-8 bytes.

The message format of CoAP contains the following fields:

CoAP Message Format

Applications of CoAP

The difference between MQTT and CoAP protocols could be understood from the following article on GFG: Difference between CoAP and MQTT

Conclusion

A lot of modern world tasks could be eased out with the help of CoAP protocols. Due to less overhead and capability to transfer data effectively even under low bandwidth, CoAP has became a primarily choice for IoT and cloud computing system architecture. CoAP messages have a fixed size header which is of 4 bytes. Alongside this, CoAP message format have some optional fields which includes fields like token, options, and payload. This message format of CoAP is binary encoded in 0/1 format. CoAP works on request response model which majorly resembles HTTP methods like GET, POST, PUT, and DELETE along with its own unique method Observe

Frequently Asked Questions on CoAP – FAQs

What is CoAP?

CoAP is an application layer protocol or more formerly, a web-based protocol that resembles HTTP which is based on the request-response model. Through this, the data from one resource to another resource is transferred in the form of CoAP message.

What are the 5 methods of CoAP?

The five methods of CoAP are as follows:

1. GET

2. POST

3. PUT

4. DELETE

5. OBSERVE

Give some applications of CoAP protocol?

Some of the most common applications of the CoAP protocol are as follows:

1. Real Time Monitoring in Grid

2. Defense utilities

3. Aircraft utilities


Article Tags :