README.rst
1.. zephyr:code-sample:: sockets-echo-client
2 :name: Echo client (advanced)
3 :relevant-api: bsd_sockets tls_credentials
4
5 Implement a client that sends IP packets, waits for data to be sent back, and verifies it.
6
7Overview
8********
9
10The echo-client sample application for Zephyr implements a UDP/TCP client
11that will send IPv4 or IPv6 packets, wait for the data to be sent back,
12and then verify it matches the data that was sent.
13
14The source code for this sample application can be found at:
15:zephyr_file:`samples/net/sockets/echo_client`.
16
17Requirements
18************
19
20- :ref:`networking_with_host`
21
22Building and Running
23********************
24
25There are multiple ways to use this application. One of the most common
26usage scenario is to run echo-client application inside QEMU. This is
27described in :ref:`networking_with_qemu`.
28
29There are configuration files for different boards and setups in the
30echo-client directory:
31
32- :file:`prj.conf`
33 Generic config file, normally you should use this.
34
35- :file:`overlay-ot.conf`
36 This overlay config enables support for OpenThread.
37
38- :file:`overlay-802154.conf`
39 This overlay config enables support for native IEEE 802.15.4 connectivity.
40 Note, that by default IEEE 802.15.4 L2 uses unacknowledged communication. To
41 improve connection reliability, acknowledgments can be enabled with shell
42 command: ``ieee802154 ack set``.
43
44- :file:`overlay-bt.conf`
45 This overlay config enables support for Bluetooth IPSP connectivity.
46
47- :file:`overlay-qemu_802154.conf`
48 This overlay config enables support for two QEMU's when simulating
49 IEEE 802.15.4 network that are connected together.
50
51- :file:`overlay-tls.conf`
52 This overlay config enables support for TLS.
53
54Build echo-client sample application like this:
55
56.. zephyr-app-commands::
57 :zephyr-app: samples/net/sockets/echo_client
58 :board: <board to use>
59 :conf: <config file to use>
60 :goals: build
61 :compact:
62
63Example building for the nrf52840dk_nrf52840 with OpenThread support:
64
65.. zephyr-app-commands::
66 :zephyr-app: samples/net/sockets/echo_client
67 :host-os: unix
68 :board: nrf52840dk_nrf52840
69 :conf: "prj.conf overlay-ot.conf"
70 :goals: run
71 :compact:
72
73Example building for the IEEE 802.15.4 RF2XX transceiver:
74
75.. zephyr-app-commands::
76 :zephyr-app: samples/net/sockets/echo_client
77 :host-os: unix
78 :board: [atsamr21_xpro | sam4s_xplained | sam_v71_xult]
79 :gen-args: -DEXTRA_CONF_FILE=overlay-802154.conf
80 :goals: build flash
81 :compact:
82
83In a terminal window you can check if communication is happen:
84
85.. code-block:: console
86
87 $ minicom -D /dev/ttyACM1
88
89
90
91Enabling TLS support
92====================
93
94Enable TLS support in the sample by building the project with the
95``overlay-tls.conf`` overlay file enabled, for example, using these commands:
96
97.. zephyr-app-commands::
98 :zephyr-app: samples/net/sockets/echo_client
99 :board: qemu_x86
100 :conf: "prj.conf overlay-tls.conf"
101 :goals: build
102 :compact:
103
104An alternative way is to specify ``-DEXTRA_CONF_FILE=overlay-tls.conf`` when
105running ``west build`` or ``cmake``.
106
107The certificate and private key used by the sample can be found in the sample's
108``src`` directory. The default certificates used by Socket Echo Client and
109:zephyr:code-sample:`sockets-echo-server` enable establishing a secure connection
110between the samples.
111
112SOCKS5 proxy support
113====================
114
115It is also possible to connect to the echo-server through a SOCKS5 proxy.
116To enable it, use ``-DEXTRA_CONF_FILE=overlay-socks5.conf`` when running ``west
117build`` or ``cmake``.
118
119By default, to make the testing easier, the proxy is expected to run on the
120same host as the echo-server in Linux host.
121
122To start a proxy server, for example a builtin SOCKS server support in ssh
123can be used (-D option). Use the following command to run it on your host
124with the default port:
125
126For IPv4 proxy server:
127
128.. code-block:: console
129
130 $ ssh -N -D 0.0.0.0:1080 localhost
131
132For IPv6 proxy server:
133
134.. code-block:: console
135
136 $ ssh -N -D [::]:1080 localhost
137
138Run both commands if you are testing IPv4 and IPv6.
139
140To connect to a proxy server that is not running under the same IP as the
141echo-server or uses a different port number, modify the following values
142in echo_client/src/tcp.c.
143
144.. code-block:: c
145
146 #define SOCKS5_PROXY_V4_ADDR IPV4_ADDR
147 #define SOCKS5_PROXY_V6_ADDR IPV6_ADDR
148 #define SOCKS5_PROXY_PORT 1080
149
150Running echo-server in Linux Host
151=================================
152
153There is one useful testing scenario that can be used with Linux host.
154Here echo-client is run in QEMU and echo-server is run in Linux host.
155
156To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
157
158In a terminal window:
159
160.. code-block:: console
161
162 $ sudo ./echo-server -i tap0
163
164Run echo-client application in QEMU:
165
166.. zephyr-app-commands::
167 :zephyr-app: samples/net/sockets/echo_client
168 :host-os: unix
169 :board: qemu_x86
170 :conf: "prj.conf overlay-linux.conf"
171 :goals: run
172 :compact:
173
174Note that echo-server must be running in the Linux host terminal window
175before you start the echo-client application in QEMU.
176Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
177
178You can verify TLS communication with a Linux host as well. See
179https://github.com/zephyrproject-rtos/net-tools documentation for information
180on how to test TLS with Linux host samples.
181
182See the :zephyr:code-sample:`sockets-echo-server` documentation for an alternate
183way of running, with the echo-client on the Linux host and the echo-server
184in QEMU.
185