Tools and Your First Network Program¶
Build a small program before opening a socket. You will use the same CMake workflow throughout the Network course.
Course examples on GitHub
Before you start¶
Use a terminal on the Pi with Raspberry Pi OS or another Linux distribution. You need basic C++ functions, strings and exceptions; the Modern C++ course covers these. No wiring or administrator access is needed to run the examples.
Outcome: build a C++20 executable and run the network checks. All commands on this page run on the Pi.
Prepare the tools¶
Inspect the tools first:
The project needs a C++20 compiler, CMake 3.28 or later, OpenSSL 3.0 or later with development headers, and Python 3.11 or later with its ssl module for tests. OpenSSL is used in the later TLS chapter; the first programs still call Linux sockets directly. The HTTP fixture uses Python's protocol-selection option. If the tools are missing on Raspberry Pi OS, package installation is an administrative change; review its prompt:
Get a fresh practice checkout¶
Create a private directory and clone the examples. Keep the path printed by pwd; later lessons run from this category directory.
The repository contains other courses, but each category has its own build. Configure and build only network/:
Expected output:
Read the first program¶
The complete file is app/hello-network/main.cpp:
static_assert checks the language mode at compile time. CMake requests C++20 and rejects an unsupported compiler. Printing this line establishes that the build works; it does not test network access.
Run the checks¶
The current suite has 629 checks covering UDP, TCP connections, framing, deadlines, multiple clients, HTTP clients and servers, chunked bodies, connection reuse, verified TLS, HTTPS and WebSocket text/control exchanges and bounded extended lengths, message fragmentation, verified WSS, DTLS and operation-ID retries. They use temporary loopback ports and finish automatically, including three-second I/O-timeout checks. The TLS checks generate disposable practice certificates in private temporary directories; they do not change system trust. Running the checks requires no root access, internet service, firewall change or permanent process. A restricted execution environment that forbids sockets cannot run these communication checks.
To repeat with optimization:
If something differs¶
- Preset not found: run from
examples/network, not the repository root. - CMake version too old: check the installed version before proceeding.
- Compile error at
static_assert: check the compiler and CMake configuration. Operation not permittedwhen creating sockets: inspect the container or sandbox restrictions. Port 9000 does not require root.
Check your understanding¶
Does a successful build prove that a server on another computer can be reached?
Compare your reasoning
No. It checks compilation and linking. The loopback tests exercise local communication; a remote connection has additional addressing, routing and access conditions.