README.rst
1.. zephyr:code-sample:: sockets-echo-server
2 :name: Echo server (advanced)
3 :relevant-api: bsd_sockets tls_credentials
4
5 Implement a UDP/TCP server that sends received packets back to the sender.
6
7Overview
8********
9
10The echo-server sample application for Zephyr implements a UDP/TCP server
11that complements the echo-client sample application: the echo-server listens
12for incoming IPv4 or IPv6 packets (sent by the echo client) and simply sends
13them back.
14
15The source code for this sample application can be found at:
16:zephyr_file:`samples/net/sockets/echo_server`.
17
18Requirements
19************
20
21- :ref:`networking_with_host`
22
23Building and Running
24********************
25
26There are multiple ways to use this application. One of the most common
27usage scenario is to run echo-server application inside QEMU. This is
28described in :ref:`networking_with_qemu`.
29
30There are configuration files for different boards and setups in the
31echo-server directory:
32
33- :file:`prj.conf`
34 Generic config file, normally you should use this.
35
36- :file:`overlay-ot.conf`
37 This overlay config enables support for OpenThread.
38
39- :file:`overlay-802154.conf`
40 This overlay config enables support for native IEEE 802.15.4 connectivity.
41 Note, that by default IEEE 802.15.4 L2 uses unacknowledged communication. To
42 improve connection reliability, acknowledgments can be enabled with shell
43 command: ``ieee802154 ack set``.
44
45- :file:`overlay-qemu_802154.conf`
46 This overlay config enables support for two QEMU's when simulating
47 IEEE 802.15.4 network that are connected together.
48
49- :file:`overlay-tls.conf`
50 This overlay config enables support for TLS.
51
52- :file:`overlay-tunnel.conf`
53 This overlay config enables support for IP tunneling.
54
55- :file:`overlay-vlan.conf`
56 This overlay config enables support for Virtual LAN.
57 See :ref:`networking_samples_common` for details.
58
59Build echo-server sample application like this:
60
61.. zephyr-app-commands::
62 :zephyr-app: samples/net/sockets/echo_server
63 :board: <board to use>
64 :conf: <config file to use>
65 :goals: build
66 :compact:
67
68Example building for the nrf52840dk/nrf52840 with OpenThread support:
69
70.. zephyr-app-commands::
71 :zephyr-app: samples/net/sockets/echo_server
72 :host-os: unix
73 :board: nrf52840dk/nrf52840
74 :conf: "prj.conf overlay-ot.conf"
75 :goals: run
76 :compact:
77
78Example building for the samr21_xpro with RF2XX driver support:
79
80.. zephyr-app-commands::
81 :zephyr-app: samples/net/sockets/echo_server
82 :host-os: unix
83 :board: [samr21_xpro | sam4e_xpro | sam_v71_xult/samv71q21]
84 :gen-args: -DEXTRA_CONF_FILE=overlay-802154.conf
85 :goals: build flash
86 :compact:
87
88In a terminal window you can check if communication is happen:
89
90.. code-block:: console
91
92 $ minicom -D /dev/ttyACM0
93
94Enabling TLS support
95====================
96
97Enable TLS support in the sample by building the project with the
98``overlay-tls.conf`` overlay file enabled, for example, using these commands:
99
100.. zephyr-app-commands::
101 :zephyr-app: samples/net/sockets/echo_server
102 :board: qemu_x86
103 :conf: "prj.conf overlay-tls.conf"
104 :goals: build
105 :compact:
106
107An alternative way is to specify ``-DEXTRA_CONF_FILE=overlay-tls.conf`` when
108running ``west build`` or ``cmake``.
109
110The certificate used by the sample can be found in the sample's ``src``
111directory. The default certificates used by Socket Echo Server and
112:zephyr:code-sample:`sockets-echo-client` enable establishing a secure connection
113between the samples.
114
115Running echo-client in Linux Host
116=================================
117
118There is one useful testing scenario that can be used with Linux host.
119Here echo-server is run in QEMU and echo-client is run in Linux host.
120
121To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
122
123Run echo-server application in QEMU:
124
125.. zephyr-app-commands::
126 :zephyr-app: samples/net/sockets/echo_server
127 :host-os: unix
128 :board: qemu_x86
129 :goals: run
130 :compact:
131
132In a terminal window:
133
134.. code-block:: console
135
136 $ sudo ./echo-client -i tap0 2001:db8::1
137
138Note that echo-server must be running in QEMU before you start the
139echo-client application in host terminal window.
140
141You can verify TLS communication with a Linux host as well. See
142https://github.com/zephyrproject-rtos/net-tools documentation for information
143on how to test TLS with Linux host samples.
144
145See the :zephyr:code-sample:`sockets-echo-client` sample documentation for an alternate
146way of running, with the echo-server on the Linux host and the echo-client
147in QEMU.
148