基於UnixC的簡單web伺服器

2021-09-10 06:23:43 字數 1232 閱讀 3958

t_net.h和t_net.c的**第十三天有,這裡編譯時連線打包好的動態庫即可  

doit.h

#ifndef do_it_h_

#define do_it_h_

#include#include#include#include#include#include#includetypedef struct requestreq_t;

typedef struct responseres_t;

void do_main(int fd);

//int h_acc(int fd)

#endif

doit.c

#include"doit.h"

#include#include#includechar *work_dir="/home/nan/sjw/webs/hhhlaugh";

//一定要考慮字串的結尾符號\0

static void get_request(int fd,req_t *rq)

//獲取檔案型別 content-type

static char *get_ftype(const char *file)

static void orgn_response(const char *file,res_t *rs)

//static void res_b_200(int fd,req_t *rq,res_t *rs)

int a=execlp("cat","cat",rq->path,null);

if(a==-1)

perror("execlp");

return;

}void do_main(int fd);

// strcat(buf,"");

//傳送

/*char buf[1024];

int r=read(fd,buf,1024);

write(1,buf,r);*/

return;

}

server.c

#include#include"doit.h"

#include#include#include#include#includevoid handle(int n)

int main()else

} return 0;

}

使用瀏覽器    登入127.0.0.1:3333/index.html

基於epoll實現簡單的web伺服器

epoll 是 linux 平台下特有的一種 i o 復用模型實現,於 2002 年在 linux kernel 2.5.44 中被引入。在 epoll 之前,unix linux 平台下的 i o 復用模型包含 select 和 poll 兩個系統呼叫。隨著網際網路的發展,網際網路的使用者量越來越...

基於epoll實現簡單的web伺服器

epoll 是 linux 平台下特有的一種 i o 復用模型實現,於 2002 年在 linux kernel 2.5.44 中被引入。在 epoll 之前,unix linux 平台下的 i o 復用模型包含 select 和 poll 兩個系統呼叫。隨著網際網路的發展,網際網路的使用者量越來越...

基於HttpListener的web伺服器

前面兩篇文章分別介紹了基於原始socket的web伺服器和基於tcplistener的web伺服器,本篇文章將繼續介紹另外一種基於httplistener的。httplistener進一步的簡化了http協議的監聽,僅需通過字串的方法提供監聽的位址和埠號以及虛擬路徑,就可以開始監聽工作了。設定字首,...