> For the complete documentation index, see [llms.txt](https://alfredo-reyes-montero.gitbook.io/iot-bosch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alfredo-reyes-montero.gitbook.io/iot-bosch/devices/bosch-xdk-110/protocols/coap/overview.md).

# Overview

The highest levels of API in regards to CoAP are all provided by the Serval Stack. It offers functionality such as a server, a client or general utilities when implementing a CoAP based application. This ensures that any message sent and received will be a CoAP message and treated as such.

![](https://1555789063-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lj1MxDmShTQrCAMd7Sr%2F-Lj1MyjBj93yCY6nPMFc%2F-Lj1NZM-SyQPzKVZnhRt%2Fimport19.png?generation=1562334349590312\&alt=media)

Client Functionality

| Function                            | Description                                                                                                                                                                                                                                                                                                         |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CoapServer_initialize()`           | This function is called to initialize the CoAP client (and server) and related modules. It must be called before any other CoAP-Client related function.                                                                                                                                                            |
| `CoapServer_startInstance()`        | This function is called to start the CoAP client (and server). As input it receives a port, to which the server will listen, and a reference to a callbackfunction, which will be called every time the server receives a message.                                                                                  |
| `CoapClient_initialize()`           | If it is desired to use different UDP sockets for server and client, this function must be called for the client instead of CoapServer\_initialize. This function initializes only the client and relevant modules. Per default, this function is disabled.                                                         |
| `CoapClient_startInstance()`        | This function is called to start the CoAP client after the client has been initialized using CoapClient\_initialize. Per default, this function is disabled, if CoapClient\_initialize is disabled, as well.                                                                                                        |
| `CoapClient_request()`              | This function is called to send a message as a request. As input, it receives a message, a callback for informing about the status of sending and a callback to handle a response to this message.                                                                                                                  |
| `CoapClient_initReqMsg()`           | This function is called to initialize a message. As input, it receives the target’s IP address, its port and the pointer to a message.                                                                                                                                                                              |
| Utility                             |                                                                                                                                                                                                                                                                                                                     |
| `CoapParser_setup()`                | This function sets up a CoAP-Parser which will be used to receive certain information from a CoAP-Message, such as the code, the payload or the options. As input, it receives a variable of type CoapParser\_T and the pointer to a message.                                                                       |
| `CoapParser_getCode()`              | This function is called to receive the code of a message. As input, it receives a pointer to a message.                                                                                                                                                                                                             |
| `CoapParser_getPayload()`           | This function is called to receive the payload of a message. As input, it receives a pointer to the previously set up parser, a pointer to a payload array, and the array’s length.                                                                                                                                 |
| `CoapSerializer_setup()`            | This function sets up a CoAP-Serializer, which will be used to create a message. It handles setting options, the payload, the code, etc, for a given message. As input, it receives variable of type CoapSerializer\_T, the pointer to a message, and a code indicating whether a RESPONSE or a REQUEST is created. |
| `CoapSerializer_setCode()`          | This function is called to set the code of a message. As input, it receives the serializer, a message and the code to be set.                                                                                                                                                                                       |
| `CoapSerializer_serializePayload()` | This function is called to set the payload for a message. As input, it receives the serializer, a message pointer, the payload and the payload’s length                                                                                                                                                             |
