README.rst
1.. zephyr:code-sample:: socket-dumb-http-server
2 :name: Dumb HTTP server
3 :relevant-api: bsd_sockets net_pkt
4
5 Implement a simple, portable, HTTP server using BSD sockets.
6
7Overview
8********
9
10The sockets/dumb_http_server sample application for Zephyr implements a
11skeleton HTTP server using a BSD Sockets compatible API. The purpose of
12this sample is to show how it's possible to develop a sockets application
13portable to both POSIX and Zephyr. As such, this HTTP server example is
14kept very minimal and does not really parse an incoming HTTP request,
15just reads and discards it, and always serve a single static page. Even
16with such simplification, it is useful as an example of a socket
17application which can be accessed via a conventional web browser, or to
18perform performance/regression testing using existing HTTP diagnostic
19tools.
20
21The source code for this sample application can be found at:
22:zephyr_file:`samples/net/sockets/dumb_http_server`.
23
24Requirements
25************
26
27- :ref:`networking_with_host`
28- or, a board with hardware networking
29
30Building and Running
31********************
32
33Build the Zephyr version of the sockets/echo application like this:
34
35.. zephyr-app-commands::
36 :zephyr-app: samples/net/sockets/dumb_http_server
37 :board: <board_to_use>
38 :goals: build
39 :compact:
40
41After the sample starts, it expects connections at 192.0.2.1, port 8080.
42The easiest way to connect is by opening a following URL in a web
43browser: http://192.0.2.1:8080/ . You should see a page with a sample
44content about Zephyr (captured at a particular time from Zephyr's web
45site, note that it may differ from the content on the live Zephyr site).
46Alternatively, a tool like ``curl`` can be used:
47
48.. code-block:: console
49
50 $ curl http://192.0.2.1:8080/
51
52Finally, you can run an HTTP profiling/load tool like Apache Bench
53(``ab``) against the server::
54
55 $ ab -n10 http://192.0.2.1:8080/
56
57``-n`` parameter specifies the number of HTTP requests to issue against
58a server.
59
60Running application on POSIX Host
61=================================
62
63The same application source code can be built for a POSIX system, e.g.
64Linux. (Note: if you look at the source, you will see that the code is
65the same except the header files are different for Zephyr vs POSIX.)
66
67To build:
68
69.. code-block:: console
70
71 $ make -f Makefile.host
72
73To run:
74
75.. code-block:: console
76
77 $ ./socket_dumb_http
78
79To test, connect to http://127.0.0.1:8080/ , and follow the steps in the
80previous section.
81
82As can be seen, the behavior of the application is the same as the Zephyr
83version.
84