Professional Documents
Culture Documents
• A CoAP request is equivalent to that of HTTP and is sent by a client to request an action (using a Method
Code) on a resource (identified by a URI) on a server. The server then sends a response with a Response
Code; this response may include a resource representation.
• Unlike HTTP, CoAP deals with these interchanges asynchronously over a datagram-oriented transport such
as UDP.
• Method Codes and Response Codes included in some of these messages make them carry requests or
responses.
• requests can be carried in Confirmable and Non- confirmable messages, and responses can be carried in
these as well as piggybacked in Acknowledgement messages.
• The CoAP messaging model is based on the exchange of messages over UDP between endpoints.
CoAP architecture
• CoAP architecture is divided into two main sub‐layers:
1 Messaging 2 Request/response
• The messaging sub‐layer is responsible for reliability
and duplication of messages, while the
request/response sub‐layer is responsible for
communication.
Type (T): 2-bit unsigned integer. Indicates if this message is of type Confirmable (0), Non-confirmable
(1), Acknowledgement (2), or Reset (3).
Token Length (TKL): 4-bit unsigned integer. Indicates the length of the variable-length Token field (0-8
bytes). Lengths 9-15 are reserved, MUST NOT be sent, and MUST be processed as a message format
error.
Code: 8-bit unsigned integer, split into a 3-bit class (most significant bits) and a 5-bit detail (least
significant bits), documented as "c.dd" where "c" is a digit from 0 to 7 for the 3-bit subfield and "dd"
are two digits from 00 to 31 for the 5-bit subfield. The class can indicate a request (0), a success
response (2), a client error response (4), or a server error response (5). (All other class values are
reserved.) As a special case, Code 0.00 indicates an Empty message. In case of a request, the Code field
indicates the Request Method; in case of a response, a Response Code.
Message ID: 16-bit unsigned integer in network byte order. Used to detect message duplication and to
match messages of type Acknowledgement/Reset to messages of type Confirmable/Non- confirmable.
CoAP messages
• On the message layer, messages can either Confirmable, Non‐confirmable,
Piggyback, Reset
• Reliable Message Transmission
• CON messages are used for reliable
transmission. An endpoint re-transmits a
CON message with an exponentially
increasing back-off timer until it is properly
acknowledged or the maximum
retransmission count is reached (which is
typically 4).
• The response to a CON request can be sent
with ACK with the same MID for message
correlation (a piggybacked response),
• or in a separate CON response, which
carries a different MID generated by the
server. The separate response is useful to
avoid waiting on the client side when the
server can not respond instantly and can be
closed by responding with an empty ACK
that only contains the 4-byte base header.
Non‐confirmable
• NON messages use a best-effort strategy and are
not retransmitted in case of loss.
• A NON message can be answered with another
NON message with a new MID generated by the
sender.
• If an endpoint receives a CON or NON that it does
not know how to process, it rejects it with an RST.
• An RST message also carries the same MID as the
origin message similar to ACK, indicates failure of
the message exchange and closes corresponding
transmission.
• The upper three bits of the 8-bit Response Code number define the class of response. The lower five bits
do not have any categorization role; they give additional detail to the overall class
•2.01 Created: Indicates that the request has been successfully processed and a new
resource has been created.
•2.04 Changed: Indicates that the request has been successfully processed and the resource
has been modified.
•4.04 Not Found: Indicates that the requested resource does not exist on the server.
•5.03 Service Unavailable: Indicates that the server is currently unable to handle the request
due to temporary overloading or maintenance.
Implementation