|
| 1 | +.. _sockets-dumb-http-server-sample: |
| 2 | + |
| 3 | +Socket Dumb HTTP Server |
| 4 | +####################### |
| 5 | + |
| 6 | +Overview |
| 7 | +******** |
| 8 | + |
| 9 | +The sockets/dumb_http_server sample application for Zephyr implements a |
| 10 | +skeleton HTTP server using a BSD Sockets compatible API. The purpose of |
| 11 | +this sample is to show how it's possible to develop a sockets application |
| 12 | +portable to both POSIX and Zephyr. As such, this HTTP server example is |
| 13 | +kept very minimal and does not really parse an incoming HTTP request, |
| 14 | +just reads and discards it, and always serve a single static page. Even |
| 15 | +with such simplification, it is useful as an example of a socket |
| 16 | +application which can be accessed via a convention web browser, or to |
| 17 | +perform performance/regression testing using existing HTTP testing |
| 18 | +tools. |
| 19 | + |
| 20 | +The source code for this sample application can be found at: |
| 21 | +:file:`samples/net/sockets/dumb_http_server`. |
| 22 | + |
| 23 | +Requirements |
| 24 | +************ |
| 25 | + |
| 26 | +- :ref:`networking_with_qemu` |
| 27 | +- or, a board with hardware networking |
| 28 | + |
| 29 | +Building and Running |
| 30 | +******************** |
| 31 | + |
| 32 | +Build the Zephyr version of the sockets/echo application like this: |
| 33 | + |
| 34 | +.. code-block:: console |
| 35 | +
|
| 36 | + $ cd $ZEPHYR_BASE/samples/net/sockets/dumb_http_server |
| 37 | + $ make pristine |
| 38 | + $ make BOARD=<board_to_use> |
| 39 | +
|
| 40 | +``board_to_use`` defaults to ``qemu_x86``. In this case, you can run the |
| 41 | +application in QEMU using ``make run``. If you used another BOARD, you |
| 42 | +will need to consult its documentation for application deployment |
| 43 | +instructions. You can read about Zephyr support for specific boards in |
| 44 | +the documentation at :ref:`boards`. |
| 45 | + |
| 46 | +After the sample starts, it expects connections at 192.0.2.1, port 8080. |
| 47 | +The easiest way to connect is by opening a following URL in a web |
| 48 | +browser: http://192.0.2.1:8080/ . You should see a page with content |
| 49 | +"Plain-text example.". Alternatively, a tool like ``curl`` can be used: |
| 50 | + |
| 51 | +.. code-block:: console |
| 52 | +
|
| 53 | + $ curl http://192.0.2.1:8080/ |
| 54 | + Plain-text example. |
| 55 | +
|
| 56 | +Finally, you can run an HTTP profiling/load tool like Apache Bench |
| 57 | +(``ab``) against the server: |
| 58 | + |
| 59 | + $ ab -n10 http://192.0.2.1:8080/ |
| 60 | + |
| 61 | +``-n`` parameter specified the number of HTTP requests to issue against |
| 62 | +a server. |
| 63 | + |
| 64 | +Running application on POSIX Host |
| 65 | +================================= |
| 66 | + |
| 67 | +The same application source code can be built for a POSIX system, e.g. |
| 68 | +Linux. (Note: if you look at the source, you will see that the code is |
| 69 | +the same except the header files are different for Zephyr vs POSIX.) |
| 70 | + |
| 71 | +To build for a host POSIX OS: |
| 72 | + |
| 73 | +.. code-block:: console |
| 74 | +
|
| 75 | + $ make -f Makefile.posix |
| 76 | +
|
| 77 | +To run: |
| 78 | + |
| 79 | +.. code-block:: console |
| 80 | +
|
| 81 | + $ ./socket_dumb_http |
| 82 | +
|
| 83 | +To test, connect to http://127.0.0.1:8080/ , and follow the steps in the |
| 84 | +previous section. |
| 85 | + |
| 86 | +As can be seen, the behavior of the application is the same as the Zephyr |
| 87 | +version. |
0 commit comments