README.rst
1.. _sockets-big-http-download:
2
3Socket Big HTTP Download Example
4################################
5
6Overview
7********
8
9The sockets/big_http_download sample application for Zephyr implements
10a simple HTTP GET client using a BSD Sockets compatible API. Unlike
11the :ref:`sockets-http-get` sample application, it downloads a file of
12several megabytes in size, and verifies its integrity using hashing. It
13also performs download repeatedly, tracking the total number of bytes
14transferred. Thus, it can serve as a "load testing" application for
15the Zephyr IP stack.
16
17The source code for this sample application can be found at:
18:zephyr_file:`samples/net/sockets/big_http_download`.
19
20Requirements
21************
22
23- :ref:`networking_with_host`
24- or, a board with hardware networking
25- NAT/routing should be set up to allow connections to the Internet
26- DNS server should be available on the host to resolve domain names
27
28Building and Running
29********************
30
31Build the Zephyr version of the application like this:
32
33.. zephyr-app-commands::
34 :zephyr-app: samples/net/sockets/big_http_download
35 :board: <board_to_use>
36 :goals: build
37 :compact:
38
39After the sample starts, it issues an HTTP GET request for
40http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/hd-media/vmlinuz
41This site was selected as providing files of variety of sizes, together
42with various hashes for them, to ease external selection and verification.
43The particular file selected is 6.7MB in size, so it can show how reliably
44Zephyr streams non-trivial amounts of data, while still taking a
45reasonable amount of time to complete. While the file is downloaded, its
46hash is computed (SHA-256 is used in the source code), and an error
47message is printed if it differs from the reference value, as specified
48in the source code. After a short pause, the process repeats (in an
49infinite loop), while the total counter of the bytes received is kept.
50Thus the application can be used to test transfers of much larger amounts
51of traffic over a longer time.
52
53You can edit the source code to issue a request to any other site on
54the Internet (or on the local network, in which case no NAT/routing
55setup is needed).
56
57.. warning::
58
59 If you are doing extensive testing with this sample, please reference
60 a file on a local server or a special-purpose testing server of your own
61 on the Internet. Using files on archive.ubuntu.com is not recommended for
62 large-scale testing.
63
64Enabling TLS support
65=================================
66
67Enable TLS support in the sample by building the project with the
68``overlay-tls.conf`` overlay file enabled, for example, using these commands:
69
70.. zephyr-app-commands::
71 :zephyr-app: samples/net/sockets/big_http_download
72 :board: qemu_x86
73 :conf: "prj.conf overlay-tls.conf"
74 :goals: build
75 :compact:
76
77An alternative way is to specify ``-DOVERLAY_CONFIG=overlay-tls.conf`` when
78running ``west build`` or ``cmake``.
79
80The TLS version of this sample downloads a file from
81https://www.7-zip.org/a/7z1805.exe (1.1MB). The certificate
82used by the sample is in the sample's ``src`` directory and is configured
83to access the default website configured in the sample for TLS
84communication (https://www.7-zip.org). To access a different
85web page over TLS, you'll need to provide a different certificate
86to authenticate to that server.
87
88Note, that TLS support in the sample depends on non-posix, TLS socket
89functionality. Therefore, it is only possible to run TLS in this sample
90on Zephyr.
91
92Running application on POSIX Host
93=================================
94
95The same application source code can be built for a POSIX system, e.g.
96Linux.
97
98To build for a host POSIX OS:
99
100.. code-block:: console
101
102 $ make -f Makefile.posix
103
104To run:
105
106.. code-block:: console
107
108 $ ./big_http_download
109
110The behavior of the application is the same as the Zephyr version.
111