GithubHelp home page GithubHelp logo

sichitong / tinywebserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qinguoyi/tinywebserver

0.0 1.0 0.0 1.31 MB

Linux下C++轻量级Web服务器

Makefile 3.62% C++ 61.57% C 26.81% HTML 5.08% Roff 2.91%

tinywebserver's Introduction

TinyWebServer

Linux下的简易web服务器,实现web端用户注册,登录功能,经压力测试可以实现上万的并发连接数据交换.

Demo

  • 注册演示
  • 登录演示

测试结果

Webbench对服务器进行压力测试,可以实现上万的并发连接.

  • 并发连接总数:10500
  • 访问服务器时间:5s
  • 每秒钟响应请求数:552852 pages/min
  • 每秒钟传输数据量:1031990 bytes/sec
  • 所有访问均成功

框架

web端界面

  • 判断是否注册
  • 注册
  • 注册失败提示
  • 登录
  • 登录失败提示

web端测试

  • 服务器测试环境

    • Ubuntu版本16.04
    • MySQL版本5.7.29
  • 测试前确认已安装MySQL数据库

    //建立yourdb库
    create database yourdb set utf8;
    
    //创建user表
    USE yourdb;
    CREATE TABLE user(
        username char(50) NULL,
        passwd char(50) NULL
    )ENGINE=InnoDB;
    
    //添加数据
    INSERT INTO user(username, passwd) VALUES('name', 'passwd');
  • 修改main.c中的数据库初始化信息

    //root root为服务器数据库的登录名和密码
    connection_pool *connPool=connection_pool::GetInstance("localhost","root","root","yourdb",3306,5);
  • 修改http_conn.cpp中的数据库初始化信息

    //root root为服务器数据库的登录名和密码
    connection_pool *connPool=connection_pool::GetInstance("localhost","root","root","yourdb",3306,5);
  • 修改http_conn.cpp中的root路径

    const char* doc_root="/home/qgy/github/ini_tinywebserver/root";
  • 选择任一校验方式,代码中使用同步校验。当使用CGI时才进行如下修改,否则可跳过本步骤,直接生成server

  • CGI多进程注册/登录校验

    • 打开http_conn.cpp中CGI,关闭同步线程

      380 //同步线程登录校验
      381 //#if 0
      423 //#endif
      
      425 //CGI多进程登录校验
      426 #if 0
      495 #endif
    • 修改sign.cpp中的数据库初始化信息

      //root root为服务器数据库的登录名和密码
      connection_pool *connPool=connection_pool::GetInstance("localhost","root","root","yourdb",3306,5);
    • 生成check.cgi

      make check.cgi
    • 将生成的check.cgi放到root文件夹

      cp ./check.cgi ./root
  • 同步线程注册/登录校验

    • 关闭http_conn.cpp中CGI,打开同步线程

      380 //同步线程登录校验
      381 #if 0
      423 #endif
      
      425 //CGI多进程登录校验
      426 //#if 0
      495 //#endif
  • 生成server

    make server
  • 启动server

    server port
  • 浏览器端

    ip:port

更多资料

请关注公众号 “两猿社”.

  • 带你丰富互联网相关项目经验,轻松应对校招!!!
  • 项目模块详细讲解,在公众号内持续更新!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.