1.. zephyr:code-sample:: async-sockets-echo-select 2 :name: Asynchronous echo server using select() 3 :relevant-api: bsd_sockets 4 5 Implement an asynchronous IPv4/IPv6 TCP echo server using BSD sockets and select() 6 7Overview 8******** 9 10The sockets/echo_async_select sample application for Zephyr implements an 11asynchronous IPv4/IPv6 TCP echo server using a BSD Sockets compatible API 12with non-blocking sockets and a ``select()`` call. This is a variant of 13the :zephyr:code-sample:`async-sockets-echo` sample. 14 15The source code for this sample application can be found at: 16:zephyr_file:`samples/net/sockets/echo_async_select`. 17 18Requirements 19************ 20 21- :ref:`networking_with_host` 22- or, a board with hardware networking (including 6LoWPAN) 23 24Building and Running 25******************** 26 27Build the Zephyr version of the sockets/echo_async application like this: 28 29.. zephyr-app-commands:: 30 :zephyr-app: samples/net/sockets/echo_async_select 31 :board: <board_to_use> 32 :goals: build 33 :compact: 34 35After the sample starts, it expects connections at 192.0.2.1 (IPv4), or 362001:db8::1 (IPv6), port 4242. The easiest way to connect is: 37 38.. code-block:: console 39 40 $ telnet 192.0.2.1 4242 # use this for IPv4 41 $ telnet 2001:db8::1 4242 # or this for IPv6 42 43After a connection is made, the application will echo back any line sent to 44it. Unlike the :zephyr:code-sample:`sockets-echo` sample, this application 45supports multiple concurrent client connections. You can open 46another terminal window and run the same telnet command as above. 47The sample supports up to three connected clients, but this can be adjusted 48by changing ``NUM_FDS`` defined in the source code. 49 50Running application on POSIX Host 51================================= 52 53The same application source code can be built for a POSIX system, e.g. 54Linux. (Note: if you look at the source, you will see that the code is 55the same except the header files are different for Zephyr vs POSIX, and 56there's an additional option to set for Linux to make a socket IPv6-only). 57 58To build: 59 60.. code-block:: console 61 62 $ make -f Makefile.host 63 64To run: 65 66.. code-block:: console 67 68 $ ./socket_echo 69 70To test: 71 72.. code-block:: console 73 74 $ telnet 127.0.0.1 4242 # use this for IPv4 75 $ telnet ::1 4242 # or this for IPv6 76 77As can be seen, the behavior of the application is the same as the Zephyr 78version. 79