1
2# TCP Client example
3
4(See the README.md file in the upper level 'examples' directory for more information about examples.)
5
6The 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.
7
8## How to use example
9
10In order to create TCP server that communicates with TCP Client example, choose one of the following options.
11
12There are many host-side tools which can be used to interact with the UDP/TCP server/client.
13One command line tool is [netcat](http://netcat.sourceforge.net) which can send and receive many kinds of packets.
14Note: please replace `192.168.0.167 3333` with desired IPV4/IPV6 address (displayed in monitor console) and port number in the following command.
15
16In 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.
17
18### TCP server using netcat
19```
20nc -l 192.168.0.167 3333
21```
22
23### Python scripts
24Script example_test.py could be used as a counter part to the tcp-client project, ip protocol name (IPv4 or IPv6) shall be stated as argument. Example:
25
26```
27python example_test.py IPv4
28```
29Note that this script is used in automated tests, as well, so the IDF test framework packages need to be imported;
30please add `$IDF_PATH/tools/ci/python_packages` to `PYTHONPATH`.
31
32## Hardware Required
33
34This example can be run on any commonly available ESP32 development board.
35
36## Configure the project
37
38```
39idf.py menuconfig
40```
41
42Set following parameters under Example Configuration Options:
43
44* Set `IP version` of example to be IPV4 or IPV6.
45
46* Set `IPV4 Address` in case your chose IP version IPV4 above.
47
48* Set `IPV6 Address` in case your chose IP version IPV6 above.
49
50* Set `Port` number that represents remote port the example will connect to.
51
52Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in [examples/protocols/README.md](../../README.md) for more details.
53
54## Build and Flash
55
56Build the project and flash it to the board, then run monitor tool to view serial output:
57
58```
59idf.py -p PORT flash monitor
60```
61
62(To exit the serial monitor, type ``Ctrl-]``.)
63
64See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
65
66
67## Troubleshooting
68
69Start server first, to receive data sent from the client (application).
70