资源简介
这是一个Linux的大作业实验报告,里面包含了web服务器源码和20页的实验报告。web服务器在Linux下以c语言实现,html作为页面展示,实现了get和post方法。实验报告包含了系统需求分析,系统设计,系统实现,系统测试等内容。

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*
==================================================
********************函数声明**********************
==================================================
*/
/*
* 读取一行请求
* 参数:套接字,保存数据的buffer,buffer大小
* 返回值:请求长度
*/
int get_line(int sock char *buf int size);
/*
* 返回 200 OK
*/
void response_200(int client const char* path);
/*
* 返回 400 BAD REQUEST
*/
void response_400(int client);
/*
* 返回 404 NOT FOUND
*/
void response_404(int client);
/*
* 返回 501 Method Not Implemented
*/
void response_501(int client);
/*
* 向客户端发送文件
* 参数:客户端套接口描述字,请求地址,标记1:GET 0:POST
*/
void response_file(int client const char* path int tag);
/*
* 处理 get 的查询参数,提取客户端提交的数据,向客户端发送结果
* 参数:客户端套接口描述字,请求地址,? 后面的参数,以 & 隔开
*/
void slove_get(int client const char* path const char* query);
/*
* 处理 post 的查询参数,提取客户端提交的数据,向客户端发送结果
* 参数:客户端套接口描述字,请求地址,请求报文主体长度
*/
void slove_post(int client const char* path int cont_len);
/*
* 启动服务器
* 返回服务器套接口描述字
*/
int start(int *port);
/*
* 处理客户端请求
*/
void accept_request(int client);
/*
* 初始化为守护进程
*/
void init_daemon();
/*
==================================================
********************主函数************************
==================================================
*/
int main(int argc char* argv[]) {
FILE *fp;
int port = 8080;
if((fp=fopen(“web.log““a“)) < 0)
perror(“fopen error!\n“);
fprintf(fp“httpd running on port %d.\n“ port);
init_daemon(); //初始化为守护进程
int server_sockfd = start(&port);
puts(“开始运行“);
while (1) {
pthread_t tid; //用于声明线程ID
struct sockaddr_in client_addr;
int client_addrlen = sizeof(client_addr);
//接收客户的连接请求
int client_sockfd = accept(server_sockfd
(struct sockaddr*)& client_addr
&client_addrlen);
if (client_sockfd < 0) {
perror(“accept error!\n“);
break;
}
if (pthread_create(&tid NULL accept_request (void*)client_sockfd) != 0)
perror(“pthread_create error\n“);
}
close(server_sockfd);
fclose(fp);
return 0;
}
/*
==================================================
********************函数实现**********************
==================================================
*/
/*
* 读取一行请求
* 参数:客户端套接口描述字,保存数据的buffer,buffer大小
* 返回值:请求长度
*/
int get_line(int sock char *buf int size) {
int cnt = 0;
char c = ‘\0‘;
int n;
while ((cnt < size-1) && (c != ‘\n‘)) {
n = read(sock &c 1); //读一个字符放到c中
if (n > 0) {
if (c == ‘\r‘) {
//MSG_PEEK不会使套接字接收队列中的数据减少
n = recv(sock &c 1 MSG_PEEK);
if ((n > 0) && (c == ‘\n‘))
read(sock &c 1);
//实际上和上面MSG_PEEK是同一个字符
else
c = ‘\n‘;
}
buf[cnt
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-02-10 11:28 web服务器\
文件 1510599 2019-02-10 11:28 web服务器\web服务器文档.docx
目录 0 2019-02-10 11:27 web服务器\web项目源码\
文件 816 2019-01-09 13:05 web服务器\web项目源码\index.html
文件 78 2019-02-10 11:28 web服务器\web项目源码\readme.txt
目录 0 2019-01-16 12:01 web服务器\web项目源码\resource\
文件 25047 2019-01-09 12:29 web服务器\web项目源码\resource\123.jpg
文件 285 2019-01-09 11:05 web服务器\web项目源码\resource\GET.html
文件 297 2019-01-09 13:04 web服务器\web项目源码\resource\pho.html
文件 286 2019-01-09 11:05 web服务器\web项目源码\resource\POST.html
文件 18872 2019-01-10 11:56 web服务器\web项目源码\web
文件 11070 2019-01-09 17:45 web服务器\web项目源码\web.c
文件 56 2019-01-10 11:57 web服务器\web项目源码\web.log
相关资源
- LINUX下命令行界面的C语言细胞游戏
- 尚观培训linux许巍老师关于c语言的课
- 《Linux程序设计》第四版pdf高清电子版
- linux 0.11内核代码
- linux ac108多麦方案驱动(ac108.c)
- 共享内存 读写
- 简易web服务器的设计与实现
- 《LINUX C编程从初学到精通》光盘源码
- Linux那些事儿之我是USB core
- Linux c语言 学生成绩管理系统
- Linux开发工具手册
- Linux操作系统下C语言编程从零开始
- 基于Linux下C语言开发的员工管理系统
- 超级玛丽c++源码win32Linux平台
- UNIX/LINUX下C语言中文短信UCS2编码和解
- 嵌入式工程师必知必会 (完整高清中
- linux-2.6.24.rar
- Linux下C语言操作静态ARP表,包括增加
- c语言 linux 贪吃蛇.doc
- Linux多线程服务端编程:使用muduo C+
- libstdc++.so.6.0.23_linux7
- libstdc++-devel-4.1.2-48.el5.x86_64
- C++版仿Linux文件管理系统
- 基于SDL的贪吃蛇游戏
- 链表栈的基本操作(C语言
- 基于linux C/C++和Qt的聊天程序
- Linux+gladeGTK++C语言+mysql的模仿QQ聊天工
- 嵌入式linuxC语言程序设计基础教程
- C Programming in Linux Linux下C语言
- Linux软件工程师(C语言)实用教程_
评论
共有 条评论