CS 455/555 - Intro to Networks and Communications
Fall 2008: Tues/Thurs 3-4:15pm, Dragas 1117

Print - Admin

Announcements

Staff

Schedule

Syllabus (pdf)

Useful Links

Program 2: Simple HTTP Client and Server

Assigned: Tuesday, September 23, 2008
Due: Thursday, October 2, 2008 before class

Description Requirements Rules Testing Submission

Description

For this assignment, we will be adding socket programming and our knowledge of the HTTP protocol to build two separate applications, a very simple HTTP server and a simple HTTP client.

Notes:

  • Do not wait until the last minute to start this assignment. This program builds upon Program 1. If you had trouble with Program 1, please seek help from the TA or instructor and ask questions early.
  • CS 455 students: anything listed as 555-only is not required for you, but will be counted as extra credit if completed.

Requirements

HTTP Server

  • Take a port (between 10000 and 11000) as the only command-line argument. If given no command-line argument, print a "Usage" statement and exit.
  • Listen for an HTTP request on the given port.
  • Print the entire HTTP request that is sent to the server.
  • Send the following response to the client (and print the response):
      HTTP/1.0 404 Not Found
      Date: date and time
      Server: ODU-CS455/555-Fall07-username
      Content-Type: text/html

      <html><head><title>404 Not Found</title></head> 
      <body><h1>Not Found</h1>
      <p>The requested URL was not found on this server.
      <p>REQUEST RECEIVED:
      <pre>contents of the received request</pre>

      <hr><p><i>HTTPServer - by your name</i>
      </body></html>

You may make the HTML code sent back in the response as pretty as you wish, just as long as the HTTP request your server received is included.

  • The date and time in the response header must be in the proper format, according to RFC 2616.
  • Your server must keep processing requests until the user quits the program with Ctrl-C.
  • Your source file must be named HTTPServer.java
  • 555-only: The date and time sent by the server must be the current date and time. For 455, you may make up a date and time, as long as it is in the proper format.

Hints:

  • readLine() strips off newline characters.
  • The entire HTTP request will not be sent on a single line.
  • Use the equals() method to compare two Strings.
  • There must be a blank line between the HTTP response header and the HTTP response data.
  • See the Date() class for obtaining the current date/time and the SimpleDateFormat() class for formatting the date/time.

HTTP Client

  • Take a URL (in the format accepted for Program 1) as the only command-line argument. If given no command-line argument, print a "Usage" statement and exit.
  • If the URL does not start with "http://", print an error message and exit.
  • Connect to the host given in the URL at the port given in the URL (80, if no port given).
  • Request the path/file given in the URL. Your request must include the Host field (with the proper entry) and the User-agent field with the entry 'ODU-CS455/555'.
  • Print the request sent to the server.
  • Print the response header received from the server, followed by the response data. These must be separated with a title.
Example:
      HTTP RESPONSE HEADER:
      HTTP/1.0 200 OK
      Date: Sun, 06 Nov 1994 08:49:37 GMT
      Server: ODU-CS455/555-Fall07-mweigle
      Content-Type: text/html

      HTTP RESPONSE DATA:
      These are the contents of the requested file.
  • Your source file must be named HTTPClient.java
  • 555-only: Use the Date() class to record the time the request was sent and the time the entire response was received. Calculate and display the HTTP response time in milliseconds.

Rules

  • As with all projects, you are not permitted to work with anyone else (even students not in the class) - all of the coding and documentation must be your own.
  • Your program must compile and run on the CS Unix machines.
  • You must just use basic socket communication (send strings over the socket) to communicate with the server. You are not allowed to use the HTTPConnection class in Java.
  • You are not required to handle the following exceptions:
    • Exception in thread "main" java.net.ConnectException: Connection refused - when asking to connect to a host and port that aren't listening
    • Exception in thread "main" java.net.SocketException: Broken pipe - when the client unexpectedly dies

Testing

  • Your client will be graded on how well it satisfies the requirements in handling a set of test URLs. Your server will be graded on how well it satisfies the requirements in handling a set of HTTP requests. You should test your programs rigorously before submitting.
  • Your HTTPClient must be able to talk to your HTTPServer.
  • Your HTTPClient must be able to talk to any web server.
  • Your HTTPServer must be able to talk to any web client. For example, if your HTTPServer is running on deneb and listening to port 10089, then type the URL http://deneb.cs.odu.edu:10089 into your web browser. You can also use proxy settings to generate interesting requests. (Do not change proxy settings on lab machines!)

Submission

You must name your HTTP client source file HTTPClient.java and your HTTP server source file HTTPServer.java. Make sure that you submit all files necessary to compile your program, but do not submit the .class files.

Directions for submitting your assignment through Blackboard