Question: Assignment Write a C++ program that implements a basic HTTP server. If this is done properly, you should be able to connect to it through

Assignment Write a C++ program that implements a basic HTTP server. If this is done properly, you should be able to connect to it through a web browser, but this will not be one of the criteria for grading. The program will essentially be a loop that goes on forever (until it is killed), waiting for a client to connect. When a client connects, it accepts that connection, calls fork to make a child process, and handles communication from that client in the child process. The parent process should continue to wait for more connections, accepting them and forking as necessary. The program will accept two command line parameters: 1. the port number on which the server will be listening 2. the path to a directory that will serve as the root directory of the web server For example: % ./z123456 9001 www The requests received by the program will be of the form: GET path where the path is the path, relative to the directory specified as the second command line parameter, of the file that is being requested. There are several rules on what can constitute a valid path, and they are as follows: it must begin with a / it may contain additional / path separators to access subdirectories a single / character refers to the directory specified in command line a trailing / in the pathname can be ignored if the path refers to a directory any data in the request beyond the path should be ignored it may not contain the substring .. If the path refers to a directory, then: if the file called index.html exists in that directory, send the contents of that file to the client if not, send a list of the files in the specified directory to the client (do not include files that start with .) If the path refers to a file, then the content of the file should be sent to the client.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!