Table of Contents
The UDP module provides functionality for handling User Datagram Protocol messages. The application can communicate with remote nodes through sockets, creating a client-server architecture. You can allocate a maximum of UDP6_MAX_SOCKET_COUNT sockets, with the functionality of bind ( udp6_socket_bind ) and connect ( udp6_socket_connect ). Each socket must declare an application handler, where the user will be informed about received messages.
The destination port and destination address of incoming packets are compared with the parameters of existing sockets. If no proper socket is found, the packet is dropped.
Asynchronous Event Notification Callback on socket
The UDP socket callback informs about the internal process result, which can be either NRF_SUCCESS or one of the following errors:
| Process result | Description |
|---|---|
| UDP_BAD_CHECKSUM | Calculated checksum does not match. |
| UDP_TRUNCATED_PACKET | UDP packet is truncated. |
| UDP_MALFORMED_PACKET | UDP packet is malformed. |
- Note
- The application may take ownership of the received packet by returning IOT_IPV6_ERR_PENDING, in which case the application must take care to free it using iot_pbuffer_free .
Code examples
UDP Echo application on port 7 and any address
Creating socket with specific peer addresses and port
This code example shows how to create a socket to receive messages only on port 1000 and address 2001:db8::1, from port 2000 and peer address 2001:db8::2. In this situation, you can use udp6_socket_send instead of udp6_socket_sendto .
Configuration parameters
The following configuration parameters should be defined in
sdk_config.h
.
UDP6_DISABLE_LOG
Disables debug tracing in the module. To enable tracing, this flag must be set to 0 and ENABLE_DEBUG_LOG_SUPPORT must be set to 1.
| Description | Value |
|---|---|
| Enable debug trace | 0 |
| Disable debug trace | 1 |
| Dependencies | ENABLE_DEBUG_LOG_SUPPORT |
UDP6_DISABLE_API_PARAM_CHECK
Disables API parameter checks in the module. Set this define to 1 to disable checks on API parameters in the module.
API parameter checks are added to ensure that the correct parameters are passed to the module. These checks are useful during development phase, but they might be redundant when the application is finalized. Disabling these checks might improve performance.
| Description | Value |
|---|---|
| Enable API parameters check | 0 |
| Disable API parameters check | 1 |
| Dependencies | None |
UDP6_MAX_SOCKET_COUNT
Maximum UDP sockets managed by the module.
| Description | Value |
|---|---|
| Minimum | 0 |
| Maximum | 255 |
| Dependencies | None |