Git Product home page Git Product logo

highhttpserver's Introduction

HighHttpServer

主要参考了《UNIX网络编程卷1:套接字联网API》《UNIX网络编程卷2:进程间通信》以及更多的参考了游双的 《Linux高性能服务器编程》,跟陈硕编写的《Linux多线程服务端编程:使用muduoC++网络库》的设计 思路有部分相同。还正在慢慢学习。 Linux下的简易web服务器,实现web端用户注册,登录功能,查看资源。 注:近期要忙着做实验写论文,但是也忙着秋招,相信大家都能有好的归宿。

项目目的

看了很多相关的书籍但是没有真正的 代码入手是不行,所以从书上和网上的资源入手,“攒出”一个项目练手, 能更加理解书上的内容

更新日志

  • 解决了传输大文件问题--2020.05.28
  • [x]

困难点

1、请求较大的视频会出现网页失败情况,并在Firefox不能请求, 只能在Chrome下请求,观察日志是由于网页会突然重新发送新数据 具体情况,需要持续更新。 2、epoll的使用机制基本算弄清楚了。

功能说明

  • 注册
  • 登录
  • 请求视频文件演示

测试结果

Webbench对服务器进行压力测试,由于自己的使用的是虚拟机 只分配了1G的内存和20G的固态,导致Webbench最多fork4500的 子进程。

  • 并发连接总数:4500
  • 访问服务器时间:5s
  • 每秒钟响应请求数:404700 pages/min
  • 每秒钟传输数据量:754969 bytes/sec
  • 所有访问均成功
如果图片加载失败,请点击缩略图直接查看图片!!!

框架

如果图片加载失败,请点击缩略图直接查看图片!!!

web端界面

  • home界面
  • 注册
  • 注册失败提示
  • 登录
  • 登录失败提示

如果图片加载失败,请点击缩略图直接查看图片!!!

日志关闭

可以通过log.h中的宏定义LOG_OPEN来关闭和开启日志

web端测试

  • 服务器测试环境

    • Ubuntu版本19.10
    • MySQL版本8.0.20
  • 测试前确认已安装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 password为服务器数据库的登录名和密码
    connection_pool *connPool=connection_pool::GetInstance("localhost","root","password","yourdb",3306,5);
  • 修改http_conn.cpp中的source路径

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

  • CGI多进程注册/登录校验
    • 打开http_conn.cpp中CGI,关闭同步线程

      6 //同步线程登录校验
      7 //#define SYN
      
      9  //CGI多进程登录校验
      10 #define CGI
      • 打开日志
      在log.h中
      #define SYN
      • 关闭日志
      在log.h中
       //#define LOG_OPEN
      
    • 修改sign.cpp中的数据库初始化信息

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

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

      cp ./check.cgi ./source
  • 生成server

    make
  • 启动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.