【发布时间】:2014-09-14 04:43:13
【问题描述】:
我想知道如何制作 Apache。我想要的是制作一个允许我的计算机托管 1 个文件的程序(或脚本)。非常基础,除了教育没有意义。就在有人在 8080 端口访问我的 IP 时,它会显示 index.html
【问题讨论】:
标签: android linux apache http webserver
我想知道如何制作 Apache。我想要的是制作一个允许我的计算机托管 1 个文件的程序(或脚本)。非常基础,除了教育没有意义。就在有人在 8080 端口访问我的 IP 时,它会显示 index.html
【问题讨论】:
标签: android linux apache http webserver
这是我对服务器应用程序基本结构的想法。
/* pseudocode */
listen_fd = socket(host, port);
// fork or create thread to listen for connections
{
while (1) {
if (0 < listen(listen_fd)) {
fd = accept(listen_fd);
// add fd to a data structure you can manage. I recommend epoll.
}
}
}
// worker process or thread
{
while (1) {
// wait for events on an fd. then read data into a buffer
n = read(fd, &buf, buf_size);
// parse request however you need to... this is a lot of the art of a web server I think.
// load and serve content
response_len = alloc_and_fread("index.html", &response, response_max_size);
send(fd, response, response_len);
}
}
【讨论】: