README.rst
1.. _sockets-echo-server-sample:
2
3Socket Echo Server
4##################
5
6Overview
7********
8
9The echo-server sample application for Zephyr implements a UDP/TCP server
10that complements the echo-client sample application: the echo-server listens
11for incoming IPv4 or IPv6 packets (sent by the echo client) and simply sends
12them back.
13
14The source code for this sample application can be found at:
15:zephyr_file:`samples/net/sockets/echo_server`.
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-server application inside QEMU. This is
27described in :ref:`networking_with_qemu`.
28
29There are configuration files for different boards and setups in the
30echo-server 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-ppp.conf`
52 This overlay config enables support for PPP (Point-to-Point Protocol).
53
54- :file:`overlay-tls.conf`
55 This overlay config enables support for TLS.
56
57- :file:`overlay-tunnel.conf`
58 This overlay config enables support for IP tunneling.
59
60Build echo-server sample application like this:
61
62.. zephyr-app-commands::
63 :zephyr-app: samples/net/sockets/echo_server
64 :board: <board to use>
65 :conf: <config file to use>
66 :goals: build
67 :compact:
68
69Example building for the nrf52840dk_nrf52840 with OpenThread support:
70
71.. zephyr-app-commands::
72 :zephyr-app: samples/net/sockets/echo_server
73 :host-os: unix
74 :board: nrf52840dk_nrf52840
75 :conf: "prj.conf overlay-ot.conf"
76 :goals: run
77 :compact:
78
79Example building for the atsamr21_xpro with RF2XX driver support:
80
81.. zephyr-app-commands::
82 :zephyr-app: samples/net/sockets/echo_server
83 :host-os: unix
84 :board: [atsamr21_xpro | sam4e_xpro | sam_v71_xult]
85 :gen-args: -DEXTRA_CONF_FILE=overlay-802154.conf
86 :goals: build flash
87 :compact:
88
89In a terminal window you can check if communication is happen:
90
91.. code-block:: console
92
93 $ minicom -D /dev/ttyACM0
94
95Enabling TLS support
96====================
97
98Enable TLS support in the sample by building the project with the
99``overlay-tls.conf`` overlay file enabled, for example, using these commands:
100
101.. zephyr-app-commands::
102 :zephyr-app: samples/net/sockets/echo_server
103 :board: qemu_x86
104 :conf: "prj.conf overlay-tls.conf"
105 :goals: build
106 :compact:
107
108An alternative way is to specify ``-DEXTRA_CONF_FILE=overlay-tls.conf`` when
109running ``west build`` or ``cmake``.
110
111The certificate used by the sample can be found in the sample's ``src``
112directory. The default certificates used by Socket Echo Server and
113:ref:`sockets-echo-client-sample` enable establishing a secure connection
114between the samples.
115
116Running echo-client in Linux Host
117=================================
118
119There is one useful testing scenario that can be used with Linux host.
120Here echo-server is run in QEMU and echo-client is run in Linux host.
121
122To use QEMU for testing, follow the :ref:`networking_with_qemu` guide.
123
124Run echo-server application in QEMU:
125
126.. zephyr-app-commands::
127 :zephyr-app: samples/net/sockets/echo_server
128 :host-os: unix
129 :board: qemu_x86
130 :goals: run
131 :compact:
132
133In a terminal window:
134
135.. code-block:: console
136
137 $ sudo ./echo-client -i tap0 2001:db8::1
138
139Note that echo-server must be running in QEMU before you start the
140echo-client application in host terminal window.
141
142You can verify TLS communication with a Linux host as well. See
143https://github.com/zephyrproject-rtos/net-tools documentation for information
144on how to test TLS with Linux host samples.
145
146See the :ref:`sockets-echo-client-sample` documentation for an alternate
147way of running, with the echo-server on the Linux host and the echo-client
148in QEMU.
149