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:
- Version – The size of version field is 2 bits. It represents the version of the CoAP protocol.
- Type Code – The size of type field is 2 bits. There are four types of messages namely confirmable, non-confirmable, acknowledgement and reset represented by the bit patterns 00, 01, 10, 11 respectively.
- Option Count – The size of option count field is 4 bits. These 4 bits, means there could be a total of 16 possible options in header.
- Code – The size of code field is 8 bits. This indicates whether message is empty, request message or response message.
- Message ID – The size of message ID field is 16 bits. It is used to detect the message duplication and types of messages.
- Tokens [Optional] – The size of tokens field is variable which ranges from 0-8 bytes. It’s used to match a response with request.
- Options [Optional] – The options field in CoAP message has a variable size. It defines the type of payload message.
- Payload [Optional] – Similar to options field, the payload field has a variable size. The payload of requests or of responses is typically a representation of the requested resource or the result of the requested action.
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.
Contact Us