ICS 451 Assignment 2: C Client and Server

Assigned January 20th, to be completed by January 27th. Turn in this exercise by e-mailing to jmoroney@hawaii.edu. Only send plain text except where another format is absolutely necessary.

You are encouraged to work in groups for this exercise.

To turn in this exercise, email the TA the answers to the questions in bold.

  1. Client from instructor
  2. Run this simple HTTP client . Select at least three web sites of your choice, and run the program on those websites. Web servers usually use port 80.

    1. Give the URLs of the websites you have chosen, and the number of receive calls to obtain the home page of each of the websites.

    If you do this exercise correctly, you should be able to see the HTTP response header sent by the server, as well as the content. You will need this information in Part 5. Some websites send back a lot of data -- you may need to scroll back or look around to find a website that sends less data.

  3. Modify Client from instructor
  4. Modify the client in part 1 so it can request an arbitrary URL. You will need to use C string operations to insert the path part of the URL into the remainder of the request. Parsing the URL might use functions such as index, rindex, strstr, and the like.

    I strongly recommend using strncat and strncpy rather than strcat or strcpy. As an alternative, feel free to use snprintf, as the instructor's code does.

    Be sure your code can break a URL such as "http://manoa.hawaii.edu/records/calendar/index.html" into its components: the host name "manoa.hawaii.edu" and the path to request, "/records/calendar/index.html".

    2. Turn in your code. If your code works, also report the number of receive calls to obtain "http://manoa.hawaii.edu/records/calendar/index.html".

  5. Server from instructor
  6. Run this simple HTTP server. Run it on your local machine, and connect to it with a variety of web clients, including your own code above, and at least one normal web browser. If you are running the server on port X (for example, X could be 12345), you can connect to it from the same machine using the URL "http://localhost:X/".

    Now modify the server to print each request, so that you can see what requests your clients are sending. Remember that data you get from the network is NOT null-terminated, that is, is NOT a C string. To make it a C string, you have to add the null character '\0' after all the data characters (this may already be in the code -- only do it if necessary). Check with the instructor or TA if you do not understand this.

    3. Give the name of the web browser you used to connect to your server (Safari, IE, Firefox, etc), and state all the requests that the browser sent to the server. There may be only one request, or there may be more than one -- just observe carefully and report what the requests were.

  7. Modify Server from instructor
  8. Modify the server from the instructor to return the contents of a single file named "index.html". The header that your server returns should contain at least some of the fields that you saw in Part 1, specifically "Connection: close", "Server: X" (X is a name you choose for your server), "Content-Type: text/html", and "Content-Length: Y". Y must be the actual number of bytes in the index.html file, as obtained by calling stat or fstat.

    4. Turn in your code for the modified server.

Documentation for the Sockets API

You may find documentation for the sockets API under the Unix/Linux "man" pages. Most of the API is in Section 2 (system calls), some functions such as snprintf and index are in section 3, and address usage is in section 7 (IP and IPv6).

Computer Networks, ICS 451
Instructor: Edo Biagioni