Project 1 - A Photo Server and Client

Due - Monday, March 5, 2007

The goal of this programming assignment is to give you an opportunity to practice writing a program that communicates across a network. You will use Java to write a photo sharing application. Your client will request photos from the server and display them for the user. The server will simply respond to client requests for photos.

Your server will support the following three types of requests:
  1. Get Random Photo - If the client requests a random photo, the server will choose a file at random and return it to the client. You may assume that all photos are stored in a single directory.
  2. Get List of Photos - If the client requests a list of photos, the server will return the file names of all files in the photo directory.
  3. Get Specific Photo - If the client requests a particular photo, the server will return that photo to the client. If requesting a particular photo, the client must specify the file name for the photo. Make sure to handle the case of a client requesting a file that does not exist.
Your client will provide a graphical interface that can display a photo or a list of names. The interface will also provide the user with the ability to request display of a random photo, select a particular file name and view the associated photo, or request a view a list of the available file names. The layout is up to you. One possible design would support (1) a "Random" button that, when clicked, would fetch a random photo and display it; (2) a "List Files" button that, when clicked, would fetch a list of available photo files and display them in a list; and (3) a "Get File" button that would fetch the file selected in the list of file names.

Implementation Requirements and Hints

  1. Start by thinking about the protocol your client and server will use to communicate.
  2. Use TCP sockets to enable reliable communication.
  3. You may implement a single-threaded server.
  4. The java.awt.Toolkit class enables you to create an Image object from a byte array. The following link may be helpful for writing the code to display images: http://java.sun.com/docs/books/tutorial/2d/images/index.html.
  5. Make sure to test as you go along. For example, implement only the get/display random photo and test it before moving on.

Extra Credit Opportunity

For extra credit, integrate your client and server into a multi-threaded peer.

Due 5:30PM Monday March 5, 2007

  1. Complete and submit your working code. Place a copy of your .java files in /home/submit/cs336/username.
Note: No portion of your code may be copied from any other source including another text book, a web page, or another student (current or former). You must provide citations for any sources you have used in designing and implementing your program.
Sami Rollins