TCP/IP Server: Implementing A Simple HTTP Daemon

This program, HTTPD implements a simple HTTP Daemon, by using the portable TCP/IP interfaces.

The basic outline of the program is quite simple. After getting a connector, loop and do the following:

  1. Use TCP.Accept to get a new service. Each team will be assigned a port number by the instructor.
  2. Get a reader and a writer to the service via ConnRW interface.
  3. The requests we are interested in start with a "GET " in the input reader stream. You can use the Lex.Match for this, or role your own character by character.
  4. The rest of the input from the reader until the next carriage return ('\n') is the path requested by the web browser.
  5. Given a path requested by a "GET" message, look in the current directory of your file system for the file in question.

    So, the URL

    http://host:8080/welcome.html
    maps to the HTTP request to the server running on port 8080 of the machine "host"
    GET /welcome.html
    which can map to
    ./welcome.html
    in your file system.
  6. Open the file, and read all its contents.
  7. Write all of the contents to the writer. Flush the writer upon completion.
  8. Make sure to close the reader, the writer, and the server connection at the bottom of the loop.
When you are done building the server, run it, and then click here to test it.