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