This project was done for CS 3516: Computer Networks. For the project I independently created an HTTP client and server in C, using a simplified version of the HTTP/1.1 protocol and Unix socket commands.

To compile the project on a GNU/Linux machine, simply use the make command. This will compile the two source files, client.c and server.c into executable files http_client and http_server respectively.


To run the client, use the command:

./http_client [-p] server_url port_num

Where server_url is the address you want to connect to and port_num is the port you want to use. Include the -p switch to also print out the RTT for connecting to the server.

The program constructs and sends a valid HTTP/1.1 GET request to the specified server_url on the specified port_num (the default HTTP port is 80). It receives the server's response and reads it into a dynamically allocated buffer, then prints it onto the terminal. If the -p switch is included, it also measaures the round trip time to conncet to the server and prints it to the terminal as well.


The HTTP server can be run with the command:

./http_server port_num

The server starts listening on the given port number in an infinite loop (it must be interrupted with a termination signal to stop). When a client connects on the given port number, the server reads the HTTP request and extracts the requested filename from it. If no file is requested the default is "index.html". If the file exists in the server's root directory it returns an HTTP 200 OK response to the client, followed by the file. A sample "index.html" file has been included for testing purposes, but you can add any number of arbitrary files to serve. If the requested file doesn't exist the server sends a 404 Not Found response to the client.

After it's done sending the file the server closes the client connection and loops back to wait for another client to connect. When the server is terminated it shuts down gracefully, closing any open sockets and freeing allocated memory.