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 Server Experiment

UDP Server Experiment


UDP Server Experiment1. UDP Server Overview2. Core Concepts2.1 UDP Server Processing Flow2.2 remoteIP() / remotePort()3. Hardware Dependencies4. Project Architecture and Flow5. Source Code Details5.1 Configuration and Global Variables5.2 setup() — Start Server5.3 loop() — Echo Processing6. Operation Flow6.1 Build and Flash6.2 Operation Steps6.3 Verification Methods7. Common Issues


1. UDP Server Overview

UDP server is a "connectionless" service - simply bind to a port, and any client can send datagrams to that port. After the server receives data, it obtains the sender's address via remoteIP() and remotePort() for targeted replies. Compared to TCP servers, UDP doesn't require accept(), doesn't need to maintain connection state, and inherently supports multiple clients.

Typical Application Scenarios:

Application TypeExample
Echo ServiceReceive and reply with the same data
DNS ServerResolve domain name requests
NTP ServerProvide time synchronization

2. Core Concepts

2.1 UDP Server Processing Flow

bind(port) → Wait for datagram arrival → recvfrom() get data+sender address → Targeted reply

Key differences from TCP server:

 UDP ServerTCP Server
ConnectionConnectionless, handle whoever sendsNeed accept() to establish connection
Multiple ClientsNaturally supported (each datagram independent)Need to maintain multiple client objects
ResourcesOne socket handles allOne socket per connection

2.2 remoteIP() / remotePort()

After parsePacket() receives a datagram, it internally records the sender's IP and port. Subsequent calls to remoteIP() and remotePort() retrieve this information for targeted replies. Unlike TCP's client.write(), UDP requires explicitly specifying beginPacket(remoteIP, remotePort) for each reply.


3. Hardware Dependencies

Pure software experiment. Need to connect to router via WIFI-STA first. Client and server must be on the same local network.


4. Project Architecture and Flow

​x
setup()
  ├─ connectWiFi()
  ├─ udp.begin(UDP_PORT)            // Bind listening port
  └─ Print server IP and port

loop()
  ├─ udp.parsePacket() > 0 ?        // Datagram arrived?
  │    ├─ udp.read(buf)             // Read payload
  │    ├─ Construct "Server Reply: xxx"
  │    └─ beginPacket(remoteIP(), remotePort()) → write → endPacket
  └─ delay(10)

5. Source Code Details

Complete source code: Source code → Arduino → 3.Network Communication → UDP_Server → UDP_Server.ino

5.1 Configuration and Global Variables

xxxxxxxxxx
#include <WiFiUDP.h>
WiFiUDP udp;
uint16_t UDP_PORT = 8080;

5.2 setup() — Start Server

xxxxxxxxxx
void setup() {
  Serial.begin(115200);
  connectWiFi();
  udp.begin(UDP_PORT);   // socket() → bind(8080)

  Serial.printf("UDP Server started | IP: %s Port: %d\n",
                WiFi.localIP().toString().c_str(), UDP_PORT);
}

5.3 loop() — Echo Processing

Reply to any received datagram with "Server Reply: ", targeted to the sender.

xxxxxxxxxx
void loop() {
  int packetSize = udp.parsePacket();
  if (packetSize > 0) {
    char buf[128];
    int len = udp.read(buf, sizeof(buf) - 1);
    buf[len] = '\0';
    Serial.printf("Received: %s\n", buf);

    char reply[160];
    sprintf(reply, "Server Reply: %s", buf);

    udp.beginPacket(udp.remoteIP(), udp.remotePort());  // Targeted reply
    udp.write(reply, strlen(reply));
    udp.endPacket();
  }
  delay(10);
}

remoteIP() and remotePort() are only valid after parsePacket() returns >0 - they correspond to the sender address of the last received datagram.


6. Operation Flow

6.1 Build and Flash

Arduino flashing process: See Arduino → 1. Before Development → 2. Build and Flash.

  1. Build and flash

  2. Use network debugging assistant or UDP client to send data to ServerIP:8080

6.2 Operation Steps

Step 1: Flash program, record server IP

Build and flash to ESP32-S3 development board. Open serial monitor (baud rate 115200), wait for WiFi connection success, and note down the server IP address printed in serial:

xxxxxxxxxx
UDP Server started | IP: 192.168.11.229 Port: 8080

Step 2: Open network debugging assistant, configure UDP client

Open network debugging assistant on PCNetwork Debugging Assistant Icon, configure with following parameters:

ParameterValue
Protocol TypeUDP
Remote HostESP32 server IP from Step 1 (e.g., 192.168.11.229)
Remote Port8080

Click "Connect" button.

Network Debugging Assistant Settings

Step 3: Send data, observe echo

Enter Hello from Client in the send area of network debugging assistant and click send. ESP32 will automatically reply with Server Reply: Hello from Client. Serial monitor and network debugging assistant will print respectively:

Network debugging assistant prints:

Network Debugging Assistant Output

Serial monitor prints:

x
18:42:38.670 -> Connecting to WiFi: Yahboom2 (Attempt 1)
18:42:39.733 -> ...
18:42:40.734 -> WiFi Connected successfully!
18:42:40.734 -> IP: 192.168.11.181
18:42:40.734 -> ==================================
18:42:40.734 ->  UDP Server Startup successful!
18:42:40.734 ->  Server IP: 192.168.11.181
18:42:40.734 ->  Port: 8080
18:42:40.734 -> ==================================
18:48:30.356 -> UDP Receive: Hello Yahboom
18:48:30.356 -> UDP Send: Server Reply: Hello Yahboom
18:48:31.037 -> UDP Receive: Hello Yahboom
18:48:31.037 -> UDP Send: Server Reply: Hello Yahboom
18:48:31.988 -> UDP Receive: Hello Yahboom
18:48:31.988 -> UDP Send: Server Reply: Hello Yahboom
18:48:32.569 -> UDP Receive: Hello Yahboom
18:48:32.569 -> UDP Send: Server Reply: Hello Yahboom

Serial Output

Step 4: Verify multi-client support

On another device, also use UDP tool to send data to ESP32's 8080 port. Each client's datagrams will be processed independently and replied to, without interference.

6.3 Verification Methods

OperationExpected Result
Client sends dataReceive "Server Reply: "
Multiple clients send simultaneouslyEach datagram replied independently, no interference

7. Common Issues

SymptomCauseSolution
Client sends but server has no responsePort mismatchConfirm client sends to port 8080 of server IP
Reply cannot be sentbeginPacket used wrong addressUse udp.remoteIP() and udp.remotePort()
WIFI AP Mode
UDP Client 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/中文