This is the documentation for the latest (main) development branch. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

UDP Server

Overview

The application creates a UDP socket with the specified port number and waits for a connection request from the client. After accepting a request from the client, connection between server and client is established and the application waits for some data to be received from the client. Received data are printed as ASCII text and retransmitted back to the client.

There are many host-side tools which can be used to interact with the UDP/TCP server/client. Only the netcat tool is used here as an example for send and receive many kinds of packets. Note: please replace 192.168.3.208 3333 with desired IPV4/IPV6 address and port number in the following command. If want to use this RECVINFO function, please enable “Enable IP_PKTINFO option” in menuconfig, this function can only resolve the destination address of IPV4.

Send UDP packet via netcat

echo "hello" | nc -w1 -u 192.168.3.208 3333

Receive UDP packet via netcat

echo "hello" | nc -w1 -u 192.168.3.208 3333

UDP server using netcat

nc -u -l 192.168.3.208 3333

Requirements

  1. A working AP is required.

  2. Configure WiFi SSID and WiFi Password in menuconfig.

  3. Configure the Port in menuconfig.

Building and flashing

Example Location: examples/network/sockets/udp_server

compile, burn, and more, see: get started

Running result

Successfully running will output the following logs

I/wm_nm_core      [5.032] got ip: 192.168.3.208
D/wm_nm_core      [5.036] WM_NM_EV post event 4 success
I/udp server      [5.542] wifi station start success, network is ready!
I/udp server      [5.550] Socket created
I/udp server      [5.554] Socket bound, port 3333
I/udp server      [5.558] Waiting for data
E/udp server      [15.562] recvfrom failed: errno 11
E/udp server      [15.568] Shutting down socket and restarting...
I/udp server      [15.574] Socket created
I/udp server      [15.580] Socket bound, port 3333
I/udp server      [15.584] Waiting for data
E/udp server      [25.586] recvfrom failed: errno 11
E/udp server      [25.592] Shutting down socket and restarting...
I/udp server      [25.598] Socket created
I/udp server      [25.604] Socket bound, port 3333
I/udp server      [25.608] Waiting for data
I/udp server      [32.734] Received 6 bytes from 192.168.3.220:
I/udp server      [32.740] hello

I/udp server      [32.746] Waiting for data