CSCI561 - Computer Networks

Program Five

Using the echo server as a starting point, create a minimal Web server.

See Chapter Six of Tanenbaum's Computer Networks, for RFC 1945 and RFC 2616, and Chapter Three of D. Comer's Computer Networks and Internets.


  1. Each time a hyperlink on a browser web page is clicked, the client broswer wraps the URL into a "GET" request for the HTTP server. Thus, your first task is to decide on a mapping scheme from client URL names to server file names. Each browser GET request will have the following form:
    	GET*Document_Name *HTTP/1.0 CRLF
    Where "*" is zero or more spaces. The "Document_Name" is an HTML file offered to the Web. "CRLF" is the combination of a carriage return and the line feed characters. "HTTP/1.0" is the protocol version. The Apache Web server reads a configuration file, but you can use program constants for your document root directory, etc. (Document root simply means the highest level default starting directory for your HTML documents.)
  2. Modify the echo server to wait for the GET request. Then read and write the named file into the socket, and close the connection.
  3. Process GET requests for HTML text files and graphic image files to be sent to the browser (client). In other words, do not mess with the file contents, just send the file as a stream of bytes.
  4. Use the last four digits of your Student ID as the port number! Do not use port 80, since you are not the superuser and you want exclusive access to your server. And you do not want fight with your classmates about whose server is whose.
  5. Test your server by invoking a Web browser. Instead of a usual URL, type in the loop back address and your port number using the following format:
    Where "localhost" is the same as and "xxxx" is the last four digits of your Student ID, the port number, and "document_name" is the file name.
  6. Test your server with another browser from a remote machine.
  7. A browser may request additional information from the server following the GET request and that additional request is delimited with a blank line (i.e., CRLF followed by another CRLF). Create a "command decode" which identify the commands such as GET, but ignores input followed by a blank line.
  8. Respond to non-existent documents with the following reply:
    	HTTP/1.0  404 File Not Found CRLF
    	Server: (Your special message) CRLF
    	Content-type: (Another message) CRLF
  9. If the document name is a directory:
    create an HTML page, in real time, containing the file names in the directory and send the resulting HTML text page to the client.
  10. Implement the HTTP 302 response that forwards the client GET request onto another Web server that can process the request.

Do not forget to kill your servers. Please clean up after yourself and do not leave your servers laying around for someone else to kill. They will fill the process table and prevent others from completing the assignment. Thank you.

Once the program is working properly, use the script program (type "man script" to see how to use it) to show your source changes, the compiler output, and the execution of the server.

This seems weird, but it works as a server demonstration. Use telnet to connect to your server. Type "GET ...", you will see the response and it will be saved in the script file.