# tcp_server_c **Repository Path**: zhaopei/tcp_server_c ## Basic Information - **Project Name**: tcp_server_c - **Description**: 原仓库地址 https://github.com/dexter-xD/tcp_server_c.git - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-13 - **Last Updated**: 2025-10-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Blink: Lightweight Web Server with Advanced Templating Blink is a lightweight, powerful web server written in C that features a comprehensive templating system with support for dynamic content, conditional logic, loops, and SQLite database integration. It's designed to be fast, easy to use, and perfect for both development and small-scale deployments. [](https://buymeacoffee.com/trish07) ## Features - **Lightweight HTTP Server**: Fast and efficient C-based HTTP server with minimal dependencies - **Hot Reloading**: Automatic browser refresh when HTML files are modified - **WebSocket Support**: Real-time bidirectional communication - **Comprehensive Templating System**: - Variable replacement - Conditional logic (if/else blocks) - Loops with item iteration - Conditional loops with filtering - Nested template structures - **SQLite Integration**: - Execute SQL queries directly in templates - Display query results as formatted HTML tables - Form-based database operations (Create, Read, Update, Delete) - Placeholder substitution for safe user input handling - **Flexible Configuration**: - Customizable port settings - Custom HTML file serving - Database path configuration - Template processing toggles ## Project Structure ``` blink/ ├── CMakeLists.txt # Build configuration ├── LICENSE # Project license ├── README.md # Project documentation ├── .gitignore # Git ignore file │ ├── include/ # Header files │ ├── blink_orm.h # ORM functionality for SQLite │ ├── debug.h # Debugging utilities │ ├── file_watcher.h # File watching for hot reload │ ├── html_serve.h # HTML serving functionality │ ├── request_handler.h # HTTP request handler │ ├── server.h # Main server header │ ├── socket_utils.h # Socket utilities │ ├── sqlite_handler.h # SQLite database integration │ ├── template.h # Template processing │ └── websocket.h # WebSocket protocol support │ ├── src/ # Source code files │ ├── file_watcher.c # Implementation of file watcher │ ├── handle_client.c # Client connection handler │ ├── html_serve.c # HTML content serving │ ├── request_handler.c # HTTP request processing │ ├── server.c # Main server implementation │ ├── socket_utils.c # Socket utility functions │ ├── sqlite_handler.c # SQLite database functions │ ├── template.c # Template engine implementation │ └── websocket.c # WebSocket implementation │ └── build/ # Build directory (generated) └── bin/ # Compiled binaries └── blink # Main executable ``` ## Quick Start ### Prerequisites - **CMake** (version 3.10 or higher) - **GCC** or another compatible C compiler - **OpenSSL** development libraries - **SQLite3** development libraries - **Linux** or **WSL** (Windows Subsystem for Linux) recommended ### Installation ```bash # Install dependencies (Debian/Ubuntu) sudo apt update sudo apt install build-essential cmake libssl-dev libsqlite3-dev # Clone the repository git clone https://github.com/dexter-xD/blink.git cd blink # Build the project mkdir build && cd build cmake .. make # Run the server ./bin/blink ``` ### Command-Line Options ``` Options: -p, --port PORT Specify port number (default: 8080) -s, --serve FILE Specify a custom HTML file to serve -db, --database FILE Specify SQLite database path -n, --no-templates Disable template processing -h, --help Display help message ``` Example usage: ```bash # Run with a custom HTML file and SQLite database ./bin/blink --serve myapp.html --database mydata.db --port 9000 ``` ## Template Engine Guide The Blink template engine allows dynamic HTML generation with various powerful features. Here's an overview of the main capabilities: ### 1. Variable Replacement Define variables using HTML comments and reference them with double curly braces: ```html
You are logged into {{company}} systems.
``` ### 2. Conditional Logic Use if-else blocks to display content conditionally: ```html {% if is_admin %}You don't have admin privileges.
{% endif %} ``` ### 3. Loops Iterate over items using for loops: ```html| Product | Category | Price |
|---|---|---|
| {{item.0}} | {{item.1}} | ${{item.2}} |
Welcome to our website.
``` ### 2. Data Dashboard with SQLite ```html