All Projects → Sakura1221 → SimpleWebServer

Sakura1221 / SimpleWebServer

Licence: other
TinyWebServer的cpp11实现,代码精简,注释详尽,比原版更容易阅读上手!新增文件上传与下载功能!

Programming Languages

C++
36643 projects - #6 most used programming language
HTML
75241 projects
CSS
56736 projects
c
50402 projects - #5 most used programming language
javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to SimpleWebServer

Butterfly Server
The Everything is Real-Time C# Backend for Single Page Applications
Stars: ✭ 247 (+268.66%)
Mutual labels:  webserver
asws
Another static web server, plus JSON REST API for exposing specified directory listings. Useful for download pages or listings asset for web applications.
Stars: ✭ 21 (-68.66%)
Mutual labels:  webserver
cookiecutter-esp32-webserver
Cookiecutter template to get you quickly started with an ESP32-based webserver project.
Stars: ✭ 13 (-80.6%)
Mutual labels:  webserver
MiServer
MiServer- an APL-based web server - requires Dyalog APL available from http://www.dyalog.com
Stars: ✭ 43 (-35.82%)
Mutual labels:  webserver
anyfesto
Low cost Raspberry Pi /Linux based access point with audio, education and communications local content server. Inspired by the ideas of sharing with others. Anyfesto - a platform from which to speak.
Stars: ✭ 66 (-1.49%)
Mutual labels:  webserver
webfr
moved to: https://github.com/godzillaframework/godzilla.git
Stars: ✭ 13 (-80.6%)
Mutual labels:  webserver
Router.cr
Minimum High Performance Middleware for Crystal Web Server.
Stars: ✭ 231 (+244.78%)
Mutual labels:  webserver
DevCeption
Inception Style (Docker inside Vagrant inside Host) Development Environment
Stars: ✭ 13 (-80.6%)
Mutual labels:  webserver
Kvantum
An intellectual (HTTP/HTTPS) web server with support for server side templating (Crush, Apache Velocity and JTwig)
Stars: ✭ 17 (-74.63%)
Mutual labels:  webserver
easy-shell
A pure Python script to easily get a reverse shell
Stars: ✭ 48 (-28.36%)
Mutual labels:  webserver
bmcweb
A do everything Redfish, KVM, GUI, and DBus webserver for OpenBMC
Stars: ✭ 109 (+62.69%)
Mutual labels:  webserver
mu-server
A lightweight modern webserver for Java
Stars: ✭ 31 (-53.73%)
Mutual labels:  webserver
foxpages
Visual FoxPro Multithread Web Server
Stars: ✭ 22 (-67.16%)
Mutual labels:  webserver
EthernetWebServer SSL
Simple TLS/SSL Ethernet WebServer, HTTP Client and WebSocket Client library for for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, ENC28J60 or Teensy 4.1 NativeEthernet/QNEthernet. It now supports Ethernet TLS/SSL Client. The library supports …
Stars: ✭ 40 (-40.3%)
Mutual labels:  webserver
DSMRloggerWS
New firmware for the DSMRlogger heavily using WebSockets and Javascript
Stars: ✭ 29 (-56.72%)
Mutual labels:  webserver
Goapp
An opinionated guideline to structure & develop a Go web application/service
Stars: ✭ 238 (+255.22%)
Mutual labels:  webserver
mf-chsdi3
api3.geo.admin.ch source code.
Stars: ✭ 35 (-47.76%)
Mutual labels:  webserver
wine
A lightweight and flexible framework to help build elegant web API
Stars: ✭ 39 (-41.79%)
Mutual labels:  webserver
hasses
Hyper's Asynchronous Server Sent event (SSE) notification Server
Stars: ✭ 18 (-73.13%)
Mutual labels:  webserver
XProc-Z
A platform for running XProc pipelines as web applications in a Java servlet container
Stars: ✭ 20 (-70.15%)
Mutual labels:  webserver

SimpleWebServer

基于Cpp11实现的高性能Web服务器,代码简洁,注释详尽,适合新手入门

特性

  • 利用Epoll与线程池实现Reactor高并发模型
  • 利用状态机与正则实现HTTP请求报文解析,可同时处理GET与POST请求
  • 用vector容器封装char,实现了一个可自动扩容的缓冲区
  • 基于epoll_wait实现定时功能,关闭超时的非活动连接,并用小根堆作为容器管理定时器
  • 利用单例模式实现了一个简单的线程池,减少了线程创建与销毁的开销
  • 利用单例模式实现连接MySQL的数据库连接池,减少数据库连接建立与关闭的开销,实现了用户注册登录功能
  • 利用单例模式与阻塞队列实现异步日志系统,记录服务器运行状态
  • 能够处理前端发送的multi/form-data类型的post请求,实现了文件上传功能
  • 通过jsoncpp生成json数据,向前端发送文件列表,实现文件展示与下载

演示

图片和视频

注册和登录

上传和下载

环境要求

  • Linux
  • C++11
  • MySQL 5.7.31
  • g++ 8.4以上

目录树

.
├── bin
│   └── simpleserver 可执行文件
├── build
│   └── Makefile
├── code             源代码
│   ├── buffer       自动扩容的缓冲区
│   ├── config       配置文件
│   ├── http         HTTP请求解析、响应
│   ├── lock         锁函数封装
│   ├── log          基于阻塞队列的异步日志模块
│   ├── main.cpp     主函数
│   ├── server       基于epoll的服务器
│   ├── sqlconnpool  数据库连接池
│   ├── threadpool   线程池
│   └── timer        小根堆管理的定时器
├── log              日志目录
├── webbench-1.5     压力测试
├── Makefile
├── README.md
└── resources        静态资源

项目启动

下载master分支(无文件上传下载功能):

git clone https://github.com/Sakura1221/SimpleWebServer.git

文件上传下载功能请切换upload分支,git clone添加-b upload选项

需要先配置好数据库

//创建数据库
create database webdb;
//创建user表
USE webdb;
CREATE TABLE user(
    username char(50) NULL,
    passwd char(50) NULL
)ENGINE=InnoDB;
//添加数据
INSERT INTO user(username, passwd) VALUES('your name', 'your password');

//webdb是数据库名,user是表名,需要在main函数中传入

然后编译运行

make
./bin/simpleserver

浏览器访问

127.0.0.1:9006
#9006是在main函数中传入的服务器监听端口

压力测试

cd webbench-1.5 && make
./webbench-1.5/webbench -c 1000 -t 5 http://ip:port/

测试平台:虚拟机Ubuntu 20.04,2C+4G,可实现8000+QPS

测试结果如图

更新记录

  • 2021/6/23 修改HTTP请求解析bug
    • 解析请求的主从状态机,由一次请求初始化一次,修改为一次连接初始化一次(避免分块发送的数据解析错误)
    • HTTP消息体可能不只一行,根据Content-Length字段,读完整后再解析(为后续form-data类型的post消息传输做准备)
  • 2021/6/25 新增upload分支
    • 该分支用于测试文件上传与下载功能,实现了文件上传,文件列表展示与下载功能(暂不支持中文名文件下载,TODO:BASE64编码)
  • 2021/6/30 新增压力测试

TODO

  • config配置

致谢

Linux高性能服务器编程,游双著

markparticle/WebServer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].