156
E. Fraccaroli and D. Quaglia
Fig. 3.35 CoAP protocol:
example of non-confirmable
message
Client
Server
NON (ID: 0x0001)
Fig. 3.36 CoAP protocol:
example of request/response
communication, where the
server can answer
immediately
Client
Server
CON (ID: 0x0001)
Token : 0x14
GET /temperature
ACK (ID: 0x0001)
Token : 0x14
GET 20 °C
Fig. 3.37 CoAP protocol:
example of request/response
communication, where the
server is initially busy
Client
Server
CON (ID: 0x0001)
Token : 0x14
GET /temperature
ACK (ID: 0x0001)
CON (ID: 0x0002)
Token : 0x14
GET 20 °C
ACK (ID: 0x0002)
3.4.6.1 CoAP Request/Response Model
The CoAP request/response model consists of confirmable and non-confirmable
messages. As shown in Fig. 3.36, if the request is carried using a confirmable
message and the server can answer immediately, the server sends back to the client
an acknowledge message containing the response or an error code. The confirmable
message also contains a Token, which is different from the ID, and it is used to
match the request and the response.
As shown in Fig. 3.37, if the server cannot answer to the request immediately,
then it sends an acknowledge message with an empty response. As soon as the
response is available, then the server sends a new confirmable message to the client
containing the response. Then, the client sends back an acknowledge message.
Figure 3.38 shows the structure of a CoAP message. It is worth noting that the
CoAP protocol is meant for constrained-size messages, and to avoid fragmentation,
a message occupies exactly the data section of a UDP packet. The CoAP message
consists of:
• Ver (2 bits): Indicates the CoAP version number.
Précédent

- 164/647

Suivant