UDP Client
Overview
The application creates a UDP socket and tries to connect to the server with predefined IP address and port number. When a connection is successfully established, the application sends message and waits for the answer. After the server’s reply, application prints received reply as ASCII text, waits for 2 seconds and sends another message.
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.220 3333
with desired IPV4/IPV6 address and port number in the following command.
Send UDP packet via netcat
echo "hello" | nc -w1 -u 192.168.3.220 3333
Receive UDP packet via netcat
echo "hello" | nc -w1 -u 192.168.3.220 3333
UDP server using netcat
nc -u -l 192.168.3.220 3333
Requirements
A working AP is required.
Configure WiFi SSID and WiFi Password in menuconfig.
Configure the IPV4 Address and Port in menuconfig.
Building and flashing
Example Location: examples/network/sockets/udp_client
compile, burn, and more, see: get started
Running result
Successfully running will output the following logs
I/wm_nm_core [5.104] got ip: 192.168.3.208
D/wm_nm_core [5.108] WM_NM_EV post event 4 success
I/udp client [5.614] wifi station start success, network is ready!
I/udp client [5.622] Socket created, sending to 192.168.3.220:3333
I/udp client [5.632] Message sent
I/udp client [12.770] Received 6 bytes from 192.168.3.220:
I/udp client [12.776] hello
I/udp client [14.782] Message sent
I/udp client [17.990] Received 4 bytes from 192.168.3.220:
I/udp client [17.996] bye