ICS 451 Assignment 1: Python Client and Server

Assigned January 13th, to be completed by January 20th. 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 textbook
  2. Run the simple HTTP client on page 58 (continuing onto page 59) of the textbook. 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 are unfamiliar with Python, be aware that Python uses indentation to show the structure of the program, so be sure your code has the same indentation as the book. Cutting and pasting could modify the indentation, in which case make sure you restore it correctly.

    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.

    If you look carefully, you will find that the header ends with "\r\n\r\n", which is an end-of-line, followed by an empty line.

  3. Modify Client from textbook
  4. Modify the client in part 1 so it can request an arbitrary URL. You will need to modify the line beginning with "s.send" to request a path other than just "/". You will also need to write some code to break up 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". The string split method might be useful for this. For example, you could use
    parts = url.split("/");
    

    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. Higher-Level Client from textbook
  6. Modify the second client from the textbook (the one that appears entirely on page 59) to take a URL as argument, and save the result in a file called "saved_web_data.html" (even though for some URLs, the data will not be HTML).

    3. Turn in your code, and state whether it works.

  7. Server from textbook
  8. Run the simple HTTP server that begins on page 60 (continuing onto page 61) of the textbook. 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.

    4. 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.

  9. Modify Server from textbook
  10. Modify the server from the textbook to return the contents of a single file named "index.html". You should manually create such a file so you can test your server -- see below if you have never created an html file before.

    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", where Y is the number of bytes in the index.html file.

    5. Turn in your code for the modified server.

    A simple index.html file might contain the following text:

    <html>
    <head><title>Web page for testing web server</title></head>
    <body>This is a web page</body>
    </html>
    




Computer Networks, ICS 451
Instructor: Edo Biagioni