|
DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
|
New here? Start with the learn index. This page assumes no prior networking knowledge.
When you load a web page, an astonishing amount happens between "click" and "page appears". To keep it understandable, engineers split the work into layers. Each layer has one job, and only talks to the layer directly above and below it. This layered map is called the OSI model (Open Systems Interconnection) - seven layers, numbered 1 (closest to the hardware) to 7 (closest to you).
You do not need to memorize it. You need the intuition: a message is built up layer by layer as it leaves one computer, and taken apart layer by layer as it arrives at the other.
Imagine mailing a birthday card to a friend in another country:
At the other end, the same steps happen in reverse: the carrier delivers it, your friend takes it out of the envelope, and reads the card. Each step only cares about its own job. The mail carrier does not read your card; you do not drive the truck.
Networking works exactly like this. Each layer wraps the data from the layer above (adds its own "envelope", called a header) and hands it down. This wrapping is called encapsulation.
We will go top-down, because that is the order data is created when you send.
The program you actually use, and the rules it speaks. A web browser speaks HTTP; an email app speaks SMTP. This layer is about meaning: "GET me the page `/index.html`".
In this library, Layer 7 is the web server you write - your routes and handlers. Code: src/network_drivers/application/ and the public API in dwserver.h.
Turns the application's meaning into a precise sequence of bytes on the wire, and back again - the "grammar" of the conversation. Parsing an HTTP request's text into fields, framing a WebSocket message, encoding JSON: all Layer 6.
Code: src/network_drivers/presentation/ (the HTTP parser, WebSocket framing, SSE, etc.).
Manages the conversation itself: who is talking, starting and ending exchanges, and deciding when work happens. In this library that is the worker task that picks up incoming data and runs the right handler.
Code: src/network_drivers/session/.
Delivers a reliable stream of bytes between two specific programs. Two key ideas live here:
Code: src/network_drivers/transport/ - this is where the library owns all socket I/O.
Gets a message across networks - from your house to a server on the other side of the planet, hopping through many routers along the way. The hero here is the IP address (like 192.168.1.85), the unique-ish number that identifies a machine on the network. Routing is "which direction do I forward this to get it closer?".
Code: src/network_drivers/network/ (IPv4, choosing which interface - e.g. Wi-Fi station vs access point - a message goes out).
Moves data between two devices on the same local link (e.g. your laptop and your home router) and wraps it in a frame. It deals with hardware addresses (MAC addresses) and detecting garbled data on that one hop.
Code: src/network_drivers/datalink/.
The actual physical thing: radio waves for Wi-Fi, electrical pulses in an Ethernet cable, light in a fiber. Pure 1s and 0s becoming real-world signals.
Code: src/network_drivers/physical/ (bringing the Wi-Fi / Ethernet hardware up and tracking whether the link is alive).
Here is the whole journey of one web request, from a browser to this server and back. Notice how each layer adds a header going down, and removes it going up:
Going down, the message gets wrapped in more and more headers (envelopes). Going up, each layer reads and strips off its header, then hands the rest upward. The browser's Layer 4 talks "logically" to the server's Layer 4, even though physically everything travels all the way down to Layer 1 and back up. That illusion - each layer chatting with its twin on the other machine - is the heart of the OSI model.
The OSI model is the teaching map. The internet itself runs on a simpler, 4-layer cousin called TCP/IP, which merges some OSI layers together. They describe the same reality at different zoom levels. Once the 7 layers make sense, read TCP/IP to see the version your devices actually use - and why this library still keeps the layers cleanly separated.
Most embedded web servers blend all of this together. This one keeps each layer in its own folder with a clean boundary, on purpose: