yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

4. UDP Client Experiment

UDP Client Experiment

UDP Client Experiment


UDP Client Experiment1. UDP Overview2. Core Concepts2.1 UDP Socket Communication Flow2.2 sendto() and recvfrom()2.3 Non-Blocking Receive (MSG_DONTWAIT)2.4 Network Byte Order3. Project Architecture and Flow3.1 UDP Client4. Hardware Dependencies5. Source Code Analysis — UDP Client5.1 Macro Configuration5.2 WiFi Initialization (Review)5.3 vUdpClientTask() — Send/Receive Loop6. Operation Flow6.1 Compilation and Flashing Flow6.2 Test Method7.3 Normal Log — Client8. Common Problems


1. UDP Overview

UDP (User Datagram Protocol) is a connectionless, unreliable but efficient transport layer protocol. Unlike TCP, UDP doesn't establish connections, doesn't guarantee delivery, doesn't guarantee order, but low overhead, low latency, very suitable for scenarios with high real-time requirements and tolerable occasional packet loss.

In IoT applications, UDP is widely used for high-frequency sensor data reporting (e.g., temperature/humidity sampled 100 times per second, losing a few frames is fine), LAN device discovery (broadcast/multicast to detect online devices in same subnet), DNS domain name resolution (small query volume, timeout retry works), and real-time audio/video streaming (latency priority over画质完整性). Mastering UDP's sendto()/recvfrom() programming model is the foundation for advanced experiments like custom protocol packing, real-time data reporting and LAN device discovery.

FeatureUDPTCP
ConnectionConnectionless, send directlyThree-way handshake to establish connection
ReliabilityNo guarantee of delivery, no guarantee of orderGuarantee delivery, guarantee order
Transmission EfficiencyHigh (8-byte header)Lower (20-byte header)
Typical UseVideo streaming, DNS, IoT sensor dataWeb, file transfer, MQTT
Core APIssendto() / recvfrom()send() / recv()

This project contains UDP client and server two sub-examples: client sends data periodically and receives server replies; server listens on port, automatically replies to received data.


2. Core Concepts

2.1 UDP Socket Communication Flow

┌─── UDP Client ──────────────────────┐    ┌─── UDP Server ──────────────────────┐
│                                    │    │                                    │
│  socket(AF_INET, SOCK_DGRAM, 0)    │    │  socket(AF_INET, SOCK_DGRAM, 0)    │
│  ↓                                 │    │  ↓                                 │
│  (No need for bind, system auto-assigns port)         │    │  bind(INADDR_ANY, 8080)            │
│  ↓                                 │    │  ↓                                 │
│  sendto(192.168.11.183:8080, data) │───→│  recvfrom() ← Received "Hello..."       │
│  ↓                                 │    │  ↓                                 │
│  recvfrom() ← Receive reply           │←───│  sendto() → Reply "I am ESP32..."   │
│                                    │    │                                    │
└────────────────────────────────────┘    └────────────────────────────────────┘

2.2 sendto() and recvfrom()

sendto() and recvfrom() are the two core APIs for UDP programming - the former sends datagrams with target address, the latter receives data while getting sender address for reply.

​x
// Send: specify target IP and port
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
               const struct sockaddr *dest_addr, socklen_t addrlen);

// Receive: also get sender address (for reply)
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
                  struct sockaddr *src_addr, socklen_t *addrlen);

2.3 Non-Blocking Receive (MSG_DONTWAIT)

MSG_DONTWAIT flag makes recvfrom() non-blocking - returns -1 immediately (errno=EAGAIN) when no data without blocking task. This example uses 10ms high-frequency polling, ensuring low-latency receive while not affecting timed sending:

xxxxxxxxxx
WIFI AP Mode
UDP Server Experiment

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文