CISC370-010 Project 6


Assigned: July 16, 2001; Due: August 1, 2001
Serving our Animals!
This project counts for 20% of the overall grade

Summary/Objective


In this project, we will be putting together several of the topics we have covered. Specifically we will be coding a client/server version of Project 4 (recall the Animal class and it's subclasses along with the GUI). The main objective is to learn how to write client/server programs in Java, with a given protocol. Secondary objectives are to learn how to use threads in Java with the server program, more experience with using streams, more GUI code with the client and continued software extending and maintenance.

The Main Idea

The main idea for this project is to create a threaded TCP server to act as a database server for our animals. After the server is in place, you will write a client to communicate with your server. Finally, you will be integrating your client class with your GUI from project 4 to act as the client.

Where to Start

The first thing we need to think about is how to actually get our animals from the server to the client. The storage Vector (or ArrayList) is now stored on the running server! You will need to write readNet(Socket) and writeNet(Socket) methods for your Animals, very similar to write/readAnimal(FileInputStream) from project 3. Using the java.net.Socket.get(In/Out)put stream, you will be able to send and receive each element over the network.

Protocol

Next, you need to implement the following protocol for your server and client to communicate with.

                  Animal DB Protocol

Strings from Client to Server:

1) Server waits for connections.
2) Client connects to server.

3) Client asks for number of objects avaliable <
   ->"number"
   <-"#"
   (Client: goto 4)

3.5) Client needs list <
   ->"listname"
   for(#) {from 3}
   ->"#"
   <-"NAME"

4.-5) Client asks for number x <
   ->"request"
   ->"#"
   <-"Type" (being Cat, Dog, etc...)
   Client makes new type
   ->newCat.readNet(socket);
   <-storage.elementAt(x).writeNet(socket);
   ok so newCat is avaliable
(Remain in interface mode) GUI~

4.5) Client asks for name "X" <
   ->"name"
   ->"X"
   <-number
   (goto 4)

5) Client says delete number x (goto 3) <
  ->"delete"
  ->"#"
  <-"deleted"
  (remove element from vector)

6) Client wants to add (goto 3) <
  ->"add"
  ­>"Type" (being Cat, Dog, etc...)
  <-(Server - newCat.readNet(socket))
  ->(Client - created.writeNet(socket))

7) Client wishes to quit <
  ->"quit"
  ~ (Server saves changes to the db file)

You will need to do this for each function, formally: You may need to add more functionality such as finding out how many elements are on the server.

More info on the client and server

The server should take two command line arguments (The port number to listen on and the name of the database file). It should readin the database to memory and then listen for a client connection. It is only required that one client is able to work at a time, but you should still implement the Runnable interface, so support for multiple concurrent clients could be added. After the client disconnects the server should save the database if it changed and listen for another client connection.
The client should take two command line arguments (The hostname the server is running on and the port number it is listening on). It should have a GUI similar to project 4, but make all database accesses over the network with the server.

Sample Run

Since this project is better explained graphically, here are some screen shots of the programs running. In the left xterm, the server is running and sending information to stdout, in the right xterm, the client is doing the same. Above those windows is the GUI from project 4 re-written to be a database client for our server. Screen Shot
Screen Shot

Turn In:

Extra Credit

To receive up to 10 points extra credit, write the server so that it will accept multiple concurrent clients by creating a thread to handle each client connection. If you do this clearly indicate it on your submission. You also have to decide how the database should be saved and updated while having multiple clients and explain this well in your documentation.

Grading

  1. Working Server (that works with one client at a time) - 50%
  2. Working Client GUI - 40%
  3. JavaDoc on WebPage - 10%