Network Programming on Raspberry Pi¶
Send a reading from your Pi to another program, then to a browser. Explore how the protocols fit together before building small C++ programs.
How TCP, UDP, HTTP and TLS fit together¶
Choose a protocol. Follow its path from your application to the network.
HTTPS with HTTP/1.1 or HTTP/2: HTTP → TLS → TCP → IP.
HTTPS with HTTP/3: HTTP/3 → QUIC → UDP → IP. QUIC integrates the TLS 1.3 handshake.
WebSocket provides two-way messages; WSS adds protection. DTLS protects datagram communication.
UDP and TCP: what reaches your program?¶
Send 1 → 2 → 3. Try delaying or losing 2, and compare the arrival order with the data available to the application.
If 2 is delayed, UDP can deliver 1 → 3 → 2. TCP holds later bytes until the missing bytes arrive, making them available in order: 1 → 2 → 3.
If 2 is lost, UDP does not resend it. TCP attempts recovery by retransmission.
UDP preserves message boundaries. TCP provides an ordered byte stream; your code still needs to find message boundaries.
About these diagrams
Numbers identify UDP messages or consecutive TCP byte ranges, not TCP application messages. The example shows successful TCP recovery; real connections can time out or fail. Steps illustrate events, not their timing.
The stack explorer shows selected protocol mappings. Its WebSocket paths use an HTTP/1.1 opening handshake. QUIC integrates TLS for its handshake and protects its own packets.
Specifications: UDP, TCP, HTTP, WebSocket, DTLS, QUIC, TLS in QUIC, HTTP/3.
What you will build¶
Part 1: Foundations¶
Part 2: UDP¶
Part 3: TCP¶
- Your First TCP Connection
- Message Boundaries in a TCP Stream
- Disconnection and Timeouts
- Multiple TCP Connections
Part 4: HTTP¶
- Your First HTTP Request
- HTTP Headers and Body Length
- A Small HTTP Server
- Chunked HTTP Bodies
- HTTP Connection Reuse
Part 5: TLS and HTTPS¶
Part 6: WebSocket¶
- Opening Handshake
- Text Frames and Clean Closure
- Ping and Pong
- Extended Payload Lengths
- Fragmented Messages
- WebSocket over Verified TLS
Part 7: DTLS¶
Part 8: QUIC and HTTP/3¶
- QUIC Streams and Toolchain
- Your First Verified QUIC Stream
- Multiple QUIC Streams
- Your First HTTP/3 Request
C++ examples on GitHub use CMake and run on one Pi. Basic C++ is enough; no additional hardware is needed.
Check yourself: If 3 arrives before 2, which protocol waits before making those later bytes available to your program?
Answer
TCP. UDP can deliver message 3 before message 2.
Start with Tools and Your First Network Program.