1 2# TCP Server 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 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. 7 8## How to use example 9 10In order to create TCP client that communicates with TCP server 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 client using netcat 19``` 20nc 192.168.0.167 3333 21``` 22 23### Python scripts 24Script example_test.py could be used as a counter part to the tcp-server application, 25IP address and the message to be send to the server shall be stated as arguments. Example: 26 27``` 28python example_test.py 192.168.0.167 Message 29``` 30Note that this script is used in automated tests, as well, so the IDF test framework packages need to be imported; 31please add `$IDF_PATH/tools/ci/python_packages` to `PYTHONPATH`. 32 33## Hardware Required 34 35This example can be run on any commonly available ESP32 development board. 36 37## Configure the project 38 39``` 40idf.py menuconfig 41``` 42 43Set following parameters under Example Configuration Options: 44 45* Set `IP version` of the example to be IPV4 or IPV6. 46 47* Set `Port` number of the socket, that server example will create. 48 49* Set `TCP keep-alive idle time(s)` value of TCP keep alive idle time. This time is the time between the last data transmission. 50 51* Set `TCP keep-alive interval time(s)` value of TCP keep alive interval time. This time is the interval time of keepalive probe packets. 52 53* Set `TCP keep-alive packet retry send counts` value of TCP keep alive packet retry send counts. This is the number of retries of the keepalive probe packet. 54 55Configure 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. 56 57## Build and Flash 58 59Build the project and flash it to the board, then run monitor tool to view serial output: 60 61``` 62idf.py -p PORT flash monitor 63``` 64 65(To exit the serial monitor, type ``Ctrl-]``.) 66 67See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. 68 69 70## Troubleshooting 71 72Start server first, to receive data sent from the client (application). 73