Tinyhttp服务器编译运行
源码下载
下载Tinyhttp源码,网址http://sourceforge.net/projects/tinyhttpd/files/latest/download
修改httpd.c源码
1、声明函数修改如下 //void accept_request(int); void *accept_request(void *); 2、定义函数修改如下: //void accept_request(int client) void *accept_request(void *client1) { // 新增下面一行代码 int client = *(int *)client1; ... if (strcasecmp(method, "GET") && strcasecmp(method, "POST")) { unimplemented(client); //return; // 新增下面一行代码 return NULL; } ... close(client); // 新增返回值 return NULL; } 3、startup函数中 //int namelen = sizeof(name); socklen_t namelen = sizeof(name); 4、main函数中 //int client_name_len = sizeof(client_name); socklen_t client_name_len = sizeof(client_name); 5、main函数中 //if (pthread_create(&newthread , NULL, accept_request, client_sock) != 0) if (pthread_create(&newthread , NULL, accept_request, (void *)&client_sock) != 0)
修改make文件
#gcc -W -Wall -lsocket -lpthread -o httpd httpd.c gcc -W -Wall -o httpd httpd.c -lpthread
进行编译
执行make 编译成功后生成httpd可执行文件
启动httd服务
由于使用的是随机端口,故打开浏览器,输入http://127.0.0.1:随机端口号即可 。
成功访问界面