Part 1
요약·해설
Internet routing, certificate 교체, Zephyr 전용 TLS와 POSIX host build의 경계를 보존합니다.
HTTP GET
IPv4 only
Zephyr · POSIX
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
33520D1CAE86C0A70B82E3CBBF29E960692868E31F12030139653AAE5484B030
.. zephyr:code-sample:: sockets-http-get
:name: HTTP GET using plain sockets
:relevant-api: bsd_sockets tls_credentials secure_sockets_options
Implement an HTTP(S) client using plain BSD sockets.
Overview
********
The sockets/http_get sample application for Zephyr implements a simple
HTTP GET client 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, it is kept minimal and
supports only IPv4.
The source code for this sample application can be found at:
:zephyr_file:`samples/net/sockets/http_get`.
Requirements
************
- :ref:`networking_with_host`
- or, a board with hardware networking
- NAT/routing should be set up to allow connections to the Internet
- DNS server should be available on the host to resolve domain names
Building and Running
********************
Build the Zephyr version of the application like this:
.. zephyr-app-commands::
:zephyr-app: samples/net/sockets/http_get
:board: <board_to_use>
:goals: build
:compact:
After the sample starts, it issues HTTP GET request to "google.com:80"
and dumps the response. You can edit the source code to issue a request
to any other site on the Internet (or on the local network, in which
case no NAT/routing setup is needed).
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
Enabling TLS support
=================================
Enable TLS support in the sample by building the project with the
``overlay-tls.conf`` overlay file enabled, for example, using these commands:
.. zephyr-app-commands::
:zephyr-app: samples/net/sockets/http_get
:board: qemu_x86
:conf: "prj.conf overlay-tls.conf"
:goals: build
:compact:
An alternative way is to specify ``-DEXTRA_CONF_FILE=overlay-tls.conf`` when
running ``west build`` or ``cmake``.
For boards that support TLS offloading (e.g. TI's cc3220sf_launchxl), use
``overlay-tls-offload.conf`` instead of ``overlay-tls.conf``.
The certificate used by the sample can be found in the sample's ``src``
directory. The certificate was selected to enable access to the default website
configured in the sample (https://google.com). To access a different web page
over TLS, provide an appropriate certificate to authenticate to that web server.
Note, that TLS support in the sample depends on non-posix, TLS socket
functionality. Therefore, it is only possible to run TLS in this sample
on Zephyr.
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:
.. code-block:: console
$ make -f Makefile.host
To run:
.. code-block:: console
$ ./http_get
As can be seen, the behavior of the application is the same as the Zephyr
version.
Part 3
한국어 전문 번역
개요
Zephyr의 sockets/http_get sample application은 BSD Sockets 호환 API를 사용해 간단한 HTTP GET client를 구현합니다.
이 sample은 POSIX와 Zephyr 양쪽에 이식할 수 있는 socket application 개발 방법을 보여 주기 위해 최소한으로 구성되었으며 IPv4만 지원합니다.
이 sample application의 source code는 samples/net/sockets/http_get에서 찾을 수 있습니다.
요구 사항
- Host system과 networking
- 또는 hardware networking 기능이 있는 board
- Internet connection을 허용하도록 NAT/routing 설정
- Domain name을 resolve할 수 있도록 host에서 이용 가능한 DNS server
빌드 및 실행
Zephyr version의 application은 다음과 같이 build합니다.
west build -b <board_to_use> samples/net/sockets/http_get
Sample이 시작되면 google.com:80으로 HTTP GET request를 보내고 response를 출력합니다. Source code를 수정하면 Internet의 다른 site에도 request를 보낼 수 있습니다. Local network의 site를 대상으로 할 때는 NAT/routing 설정이 필요하지 않습니다.
CTRL+A에 이어 x를 눌러 QEMU를 종료합니다.
TLS 지원 활성화
overlay-tls.conf overlay file을 활성화해 project를 build하면 sample의 TLS 지원을 켤 수 있습니다.
west build -b qemu_x86 samples/net/sockets/http_get -- -DCONF_FILE="prj.conf overlay-tls.conf"
다른 방법으로 west build 또는 cmake를 실행할 때 -DEXTRA_CONF_FILE=overlay-tls.conf를 지정할 수 있습니다.
TI cc3220sf_launchxl처럼 TLS offloading을 지원하는 board에서는 overlay-tls.conf 대신 overlay-tls-offload.conf를 사용합니다.
Sample이 사용하는 certificate는 sample의 src directory에 있습니다. 이 certificate는 sample의 기본 website인 https://google.com에 접근할 수 있도록 선택되었습니다. TLS로 다른 web page에 접근하려면 해당 web server를 인증하기에 적절한 certificate를 제공해야 합니다.
이 sample의 TLS 지원은 non-POSIX TLS socket 기능에 의존하므로 TLS를 사용하는 이 sample은 Zephyr에서만 실행할 수 있습니다.
POSIX Host에서 application 실행
동일한 application source code를 Linux 같은 POSIX system용으로 build할 수 있습니다. Source를 보면 Zephyr와 POSIX에서 header file만 다르고 나머지 code는 같습니다.
Build 방법:
$ make -f Makefile.host
실행 방법:
$ ./http_get
확인할 수 있듯이 application의 동작은 Zephyr version과 같습니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.