• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

tcp_client/11-Mar-2024-412289

tcp_client_multi_net/11-Mar-2024-350262

tcp_server/11-Mar-2024-419293

udp_client/11-Mar-2024-425294

udp_multicast/11-Mar-2024-681503

udp_server/11-Mar-2024-356239

README.mdD11-Mar-20244.5 KiB12279

README.md

1
2# BSD Socket API Examples
3
4This directory contains simple examples demonstrating BSD Socket API.
5Each example, contains README.md file with mode detailed informations about that particular example.
6For more general informations about all examples, see the README.md file in the upper level 'examples' directory.
7Examples:
8
9* UDP Client - The application creates UDP socket and sends message to the predefined port and IP address. After the server's reply, the application prints received reply as ASCII text, waits for 2 seconds and sends another message.
10
11* UDP Server - 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.
12
13* TCP Client - The application creates a TCP 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.
14
15* TCP Server - The application creates a TCP 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.
16
17* UDP Multicast - The application shows how to use the IPV4 & IPV6 UDP multicast features via the BSD-style sockets interface.
18
19Standard BSD API documentation:
20http://pubs.opengroup.org/onlinepubs/007908799/xnsix.html
21
22Other references:
23https://csperkins.org/teaching/2007-2008/networked-systems/lecture04.pdf
24http://wiki.treck.com/Introduction_to_BSD_Sockets
25
26
27## Host tools
28
29There are many host-side tools which can be used to interact with the UDP/TCP server/client example.
30One command line tool is [netcat](http://netcat.sourceforge.net) which can send and receive many kinds of packets.
31Note: please replace `192.168.0.167 3333` with desired IPV4/IPV6 address (displayed in monitor console) and port number in the following commands.
32
33In addition to those tools, simple Python scripts can be found under sockets/scripts directory. Every script is designed to interact with one of the examples.
34
35### Send UDP packet via netcat
36```
37echo "Hello from PC" | nc -w1 -u 192.168.0.167 3333
38```
39
40### Receive UDP packet via netcat
41```
42echo "Hello from PC" | nc -w1 -u 192.168.0.167 3333
43```
44
45### UDP client using netcat
46```
47nc -u 192.168.0.167 3333
48```
49
50### UDP server using netcat
51```
52nc -u -l 192.168.0.167 -p 3333
53```
54
55### TCP client using netcat
56```
57nc 192.168.0.167 3333
58```
59
60### TCP server using netcat
61```
62nc -l 192.168.0.167 -p 3333
63```
64
65### Python scripts
66Each script in the application directory could be used to exercise the socket communication.
67Command line arguments such as IP version (IPv4 or IPv6) and IP address and payload data (only clients) shall be supplied.
68In addition to that, port number and interface id are hardcoded in the scripts and might need to be altered to match the values used by the application. Example:
69
70```
71PORT = 3333
72INTERFACE = 'en0'
73```
74
75### Note about IPv6 addresses
76
77Examples are configured to obtain multiple IPv6 addresses. The actual behavior may differ depending on the local network, typically the ESP gets assigned these two addresses
78
79* Local Link address
80
81* Unique Local address
82
83The value and type of the IPv6 address is displayed in the terminal, for example:
84
85Please make sure that when using the Local Link address, an interface id is included in the configuration:
86
87* In the embedded code
88```
89    dest_addr.sin6_scope_id = esp_netif_get_netif_impl_index(esp_netif_instance);
90```
91* On the host
92
93   - Interface name suffix is present when passing the address as a string, for example `fe80::260a:XXX:XXX:XXX%en0`
94   - The interface id is present when passing the endpoint as tupple, for example `socket.connect(('fd00::260a:XXXX:XXXX:XXXX', 3333, 0, 3))`
95
96## Hardware Required
97
98This example can be run on any commonly available ESP32 development board.
99
100## Configure the project
101
102```
103idf.py menuconfig
104```
105
106* Specific configuration for each example can be found in its README.md file.
107
108## Build and Flash
109
110Build the project and flash it to the board, then run monitor tool to view serial output:
111
112```
113idf.py -p PORT flash monitor
114```
115
116(To exit the serial monitor, type ``Ctrl-]``.)
117
118See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
119
120
121
122