Static HTTP server
Github repositoryWhy ?
Computer Networks is one of the courses this semester. But, due to the COVID-19 pandemic, it was cut short and some of the stuff we were supposed to learn was not covered. So, I thought "may be I'll learn it online and see what I can do". This server is result of that thought.
Features
Running
gcc
and make
(optional).clone
this repository and run make
.make
run gcc -Wall server.c -o server
in root directory.
html/
directory or pass your directory name as an
argument. In anycase, the static directory must be
in the same directory as the server
binary.exit
How does it work ?
main()
sets up a listening socket, a threadpool with 8 worker threads (default) and
waits for incoming connections using epoll().pthread_cond_wait()
method and forgets about it.Benchmarks
I included a html page full of images of puppies and a script to make a 100 requests to the server and
time it. On my laptop with an i5 processor and 8 GB RAM, each request takes around a second to complete. To run the benchmark yourself, in the
root directory of this repository run bash benchmark.sh
.
$ bash benchmark.sh
Benchmark url: http://localhost:8000//benchmark/puppies/index.html
Made 100 requests
Total time: 41 s
Average time per request: 412 ms
Usage
$ ./server -h
Static HTTP server
Usage: ./server [-p port number] [-h html directory] [-t thread pool size]
[Optional arguments]
-p Server port (Default 8000)
-t Thread pool size. Number of threads for the server to use. (Default 8)
-s HTML files in this directory are served. This directory must be in the same directory as
the server binary and don't add './' to the directory name! (Default 'html')
-h Shows available arguments