How dungyichao/http_server works
Project Type and Purpose
• This is an open-source tutorial/project that implements a simple HTTP web server in C/C++ on Linux from scratch, plus two streaming extensions:
• HLS-based video streaming (using FFmpeg and file segments)
• MJPEG streaming (using a Python capture script piped into a C server)
• The goal is to teach how to parse HTTP requests, classify by MIME type, serve static content, fork per connection, and extend to live video streaming.
File Structure Analysis
• Top-level directories:
• src/ – C/C++ sources and web-content archives
• doc/ – PDF references and tutorial materials
• Project/simple_streameye/ – MJPEG demo (rasp_test.py & test001.c)
• README.md – detailed tutorial and architecture description
• Key files in src/:
• helloworld.cpp – core HTTP server implementation
• api_server/main.cpp + json.hpp – alternative C++ “API server” example
• index.html, Web_Content_1.zip, Web_Content_2.zip – static site assets
• Streaming support:
• HLS: bash script (ffmpeg-rpi-stream) invoked as a systemd service, generates .ts segments + .m3u8 playlist in a folder served by the same HTTP server
• MJPEG: rasp_test.py captures JPEG frames via raspivid; frames piped into test001 (a standalone C server derived from StreamEye) which listens on a socket and serves multipart JPEG over HTTP.
Architecture Insights from README
• Core HTTP server loop:
• socket() → bind() → listen() → accept()
• fork() per client → parse() request line for URI and extension
• classify() extension → determine MIME type header
• send_message() → write header + open/fstat/sendfile for static content
• HLS flow: raspivid → FFmpeg → disk segments (.ts + .m3u8) → HTTP GET by client → served as static files by helloworld.cpp
• MJPEG flow: rasp_test.py → stdout JPEG frames → test001 C server → HTTP clients connect to /stream.mjpg → server streams multipart JPEG.
Detail Level
• Logical module as its own component, even if it shares the same binary (e.g., static file handler vs. streaming handler within helloworld.cpp)
• Directory mounts or paths:
• /var/www/http_server/static → index.html, CSS, JS, img
• /var/www/http_server/hls → s.m3u8 + s_*.ts