esp-idf/examples/protocols/sockets/udp_server
Euripedes Rocha 4778d9b477 protocols/examples: Disable Wifi connection if not supported
- Disable Kconfig option for Wifi if not supported by the SoC
- Enable building mqtt examples when target is set to esp32h2
2023-05-30 13:26:45 +02:00
..
main CI: Improve common test methods 2022-07-15 14:21:34 +08:00
CMakeLists.txt tools: Increase the minimal supported CMake version to 3.16 2022-06-01 06:35:02 +00:00
pytest_udp_server.py CI: enable more wifi cases 2023-01-06 06:03:52 +00:00
README.md protocols/examples: Disable Wifi connection if not supported 2023-05-30 13:26:45 +02:00
sdkconfig.ci CI: update test cases to use different environment variables 2022-07-15 01:16:35 +08:00

Supported Targets ESP32 ESP32-C2 ESP32-C3 ESP32-C6 ESP32-H2 ESP32-S2 ESP32-S3

UDP Server example

(See the README.md file in the upper level 'examples' directory for more information about examples.)

The application creates UDP socket with the specified port number and waits for the data to be received. Received data are printed as ASCII text and retransmitted back to the client.

How to use example

In order to create UDP client that communicates with UDP server example, choose one of the following options.

There are many host-side tools which can be used to interact with the UDP/TCP server/client. One command line tool is netcat which can send and receive many kinds of packets. Note: please replace 192.168.0.167 3333 with desired IPV4/IPV6 address (displayed in monitor console) and port number in the following commands. If want to use this RECVINFO function, please enable LWIP_NETBUF_RECVINFO in menuconfig,this function can only resolve the destination address of IPV4.

Ref to the upper level README for more information.

Send UDP packet via netcat

echo "Hello from PC" | nc -w1 -u 192.168.0.167 3333

Receive UDP packet via netcat

echo "Hello from PC" | nc -w1 -u 192.168.0.167 3333

UDP client using netcat

nc -u 192.168.0.167 3333

Hardware Required

This example can be run on any commonly available ESP32 development board.

Configure the project

idf.py menuconfig

Set following parameters under Example Configuration Options:

  • Set IP version of the example to be IPV4 or IPV6.

  • Set Port number that represents remote port the example will create.

Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in examples/protocols/README.md for more details.

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Troubleshooting

Start server first, to receive data sent from the client (application).