zephyr/samples/net/sockets/dumb_http_server
Sebastian Bøe 55ee53ce91 cmake: Prepend 'cmake_minimum_required()' into 'app' build scripts
Prepend the text 'cmake_minimum_required(VERSION 3.8.2)' into the
application and test build scripts.

Modern versions of CMake will spam users with a deprecation warning
when the toplevel CMakeLists.txt does not specify a CMake
version. This is documented in bug #8355.

To resolve this we include a cmake_minimum_required() line into the
toplevel build scripts. Additionally, cmake_minimum_required is
invoked from within boilerplate.cmake. The highest version will be
enforced.

This patch allows us to afterwards change CMake policy CMP000 from OLD
to NEW which in turn finally rids us of the verbose warning.

The extra boilerplate is considered more acceptable than the verbosity
of the CMP0000 policy.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-08-15 04:06:50 -07:00
..
src
CMakeLists.txt cmake: Prepend 'cmake_minimum_required()' into 'app' build scripts 2018-08-15 04:06:50 -07:00
Makefile.posix
README.rst
prj.conf net: config: Rename Kconfig options to correspond to library name 2018-08-13 18:42:31 -07:00
sample.yaml samples: exclude socket samples on esp32 2018-07-16 19:00:32 -04:00

README.rst

.. _sockets-dumb-http-server-sample:

Socket Dumb HTTP Server
#######################

Overview
********

The sockets/dumb_http_server sample application for Zephyr implements a
skeleton HTTP server using a BSD Sockets compatible API. The purpose of
this sample is to show how it's possible to develop a sockets application
portable to both POSIX and Zephyr. As such, this HTTP server example is
kept very minimal and does not really parse an incoming HTTP request,
just reads and discards it, and always serve a single static page. Even
with such simplification, it is useful as an example of a socket
application which can be accessed via a convention web browser, or to
perform performance/regression testing using existing HTTP testing
tools.

The source code for this sample application can be found at:
:file:`samples/net/sockets/dumb_http_server`.

Requirements
************

- :ref:`networking_with_qemu`
- or, a board with hardware networking

Building and Running
********************

Build the Zephyr version of the sockets/echo application like this:

.. zephyr-app-commands::
   :zephyr-app: samples/net/sockets/dump_http_server
   :board: <board_to_use>
   :goals: build
   :compact:

``board_to_use`` defaults to ``qemu_x86``. In this case, you can run the
application in QEMU using ``make run``. If you used another BOARD, you
will need to consult its documentation for application deployment
instructions. You can read about Zephyr support for specific boards in
the documentation at :ref:`boards`.

After the sample starts, it expects connections at 192.0.2.1, port 8080.
The easiest way to connect is by opening a following URL in a web
browser: http://192.0.2.1:8080/ . You should see a page with a sample
content about Zephyr (captured at a particular time from Zephyr's web
site, note that it may differ from the content on the live Zephyr site).
Alternatively, a tool like ``curl`` can be used:

.. code-block:: console

    $ curl http://192.0.2.1:8080/

Finally, you can run an HTTP profiling/load tool like Apache Bench
(``ab``) against the server:

    $ ab -n10 http://192.0.2.1:8080/

``-n`` parameter specifies the number of HTTP requests to issue against
a server.

Running application on POSIX Host
=================================

The same application source code can be built for a POSIX system, e.g.
Linux. (Note: if you look at the source, you will see that the code is
the same except the header files are different for Zephyr vs POSIX.)

To build for a host POSIX OS:

.. code-block:: console

    $ make -f Makefile.posix

To run:

.. code-block:: console

    $ ./socket_dumb_http

To test, connect to http://127.0.0.1:8080/ , and follow the steps in the
previous section.

As can be seen, the behavior of the application is the same as the Zephyr
version.