Chapter 8. CoAP Server Implementation

What is your response?

I made my request again.

Finally confirmed!

In Chapters 6 and 7, we explored IoT messaging basics using the MQTT protocol for pub/sub communications. In this chapter, we’ll explore IoT messaging using request/response protocols, specifically the Constrained Application Protocol (CoAP), which has similarities to Hypertext Transfer Protocol (HTTP) but was designed for lightweight communications between devices. 

Like pub/sub, request/response is a term that captures a type of messaging interaction between two systems. This can be thought of as a peer-to-peer protocol, in which a client sends an action request to a server for a specific resource, which the server can accept or reject. A resource is just something that the server manages. This could be a static file (like a simple web page, video clip, or image), a database or other enterprise system, or one part of a more dynamic interaction that involves multiple requests and responses. In each case, the response includes some indication of the action the server took (or didn’t take) in the form of a response code.

Much like talking to an MQTT server, CoAP requires knowledge of the server’s address and the port. Once you identify the target server and port, the resource name ...

Get Programming the Internet of Things now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.