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