Assignment 1: Writing a Thread-per-Request Web Client and Server

The purpose of this assignment is to acquaint you with using the ACE C++ toolkit to perform network IPC between two host machines. We will actually be writing two programs: (1) a simple web client and (2) a simple web server. In brackets are some hints about what kinds of ACE classes you might want to look up to do these, which are described in the ACE books and ACE online documentation. The only components that you must use for this assignment are the ACE C++ socket wrapper facades and the ACE_Thread_Manager. The other hints are simply for your convenience.


Web Client

The simple web client program should do the following activities:
  1. Read the URL and the server port number from the command line. Create a socket that is connected to the server machine at the specified port (e.g., HTTP port 80) [ACE_INET_Addr, ACE_SOCK_Connector, ACE_SOCK_Stream].

  2. Send a request to the web server using the HTTP protocol format. This will look something like this:
    
    GET /index.html HTTP/1.0\n\n
    
    Note that it's very important to include the two trailing newlines -- they are required by the HTTP protocol.

  3. Read all the data from the HTTP connection and write it to a temporary file created in your web cache (e.g., using ACE_FILE_Connector::connect()) on the local host [creat,read/write].

  4. The following portion of the web client is just for the graduate students in the class. Spawn an external viewer to display the file. You can determine the type of viewer to spawn in two ways:

The client should simply print out the appropriate error message [perror] and exit with a return status of 1 if any of the system calls fail to work properly. If everything works correctly, the program should exit with a return status of 0.


Web Server

The concurrent multi-threaded server program should do the following activities:

Make sure that all resources you allocate in the program, including memory, socket, and files, are deallocated before your program exits to avoid leaks.


Comments

Although this assignment is fairly easy to describe, there are some subtleties involved in making it work correctly. In particular, you will need to learn about many details such as network addressing, remote host identification, signal handling, thread creation and termination, etc.

In addition, please note that although we will use the ACE C++ socket wrapper facades, you can actually communicate between processes on the same host for testing purposes. However, the same programs will work for communicating between processes on two separate host machines, i.e., only the addresses will be different!


References