Summer 2003
Due: 11:59pm, Monday, July 21
0. Objectives
In the first part of the project, you created the GUIs for the client and server. Currently, these GUIs do little more than print messages to the console. In this assignment you will write code in both your client program and server program to allow the server and clients to communicate, thus allowing users to log in to the server and cast votes.
Note that for this assignment you may use my solution files from part1, your solutions for part1, or any other group's solutions (with their permission, of course).
1. Client Specifications
You should modify your client to function as follows:
2. Server Specifications
In this part of the project, you will improve the server to allow it to listen
for incoming connections and serve them. First, note that the "Test vote" button from part 1 is no longer needed, so you can remove it.
The server should function as follows:
2.1 More Server Notes
The "Open", "Close", and "Refresh" buttons should still function as they did in part 1 of the project. You should remove the "Test Vote" button, however.
3. More Notes
3.1 A Note on Threads
When connecting, the client should spawn and start() a new thread to handle that connection. The reason
for this is that handling a connection takes a long time (indeed, it takes as long as the connection is open).
You'll remember that event-handling code must execute quickly, or else the GUI will freeze, so we
cannot handle the connection there. Instead, you should spawn a new thread in your event-handling code
and start() it, so that the new thread will handle the connection, and the event-handling thread will be able
to continue without delay.
On the server side, you should spawn and start() a new thread to handle each new
incoming connection. It would be impossible to serve multiple connections with one thread.
I will be talking about threads in class. You should also look at the Java Tutorial and the Java API.
Also, remember to use the "synchronized" keyword where necessary. Again, I'll explain this in class. Basically, synchronized prevents methods called from two
different threads from trying to access a data structure at the same time. If this happens, data can be corrupted.
3.2 A Note on Serialization
Serialization allows objects to be "frozen", saving their state. These serialized objects can then be sent across a network, or even saved to disk.
For this project, you should use serialization to send objects across the network. To serialize an object, you first must make sure that the object's
class implements the Serializable interface. There are no methods to write here, so just add " implements Serializable" when you declare your class. You
must also make sure that any objects contained within that class are also
serializable.
Check out the Serializable interface in the API. Also look at the ObjectInputStream and ObjectOutputStream classes, which allow you to read and
write objects to/from streams. I'll have an example of this in class, in which I save an object to a file, and then reload it.
I recommend writing a Message class, which should include all the information/objects that you want to send over the network. You can then
serialize a Message object, send it over the network, and deserialize it on the other end.
Note that if two programs are sending objects between each other, they must both
have a copy of that class in order to recognize it. In other words, if you have
a Message object, you must include Message.java in both your client and server programs.
4. Design Priorities
The software you design should show good class structure and be easy to extend. Good documentation, good structure, clean abstractions, and straightforward control flow all contribute to such extensibility. You should also make proper use of Java’s many data structures, such as hash tables, linked lists, etc. (if and where you think you need them). Think about what classes and class structure you’ll need beforehand, and what those classes should do.
5. General Specifications
Please use JDK 1.3 or higher. I highly recommend you use the latest JDK version (1.4) to avoid any problems or confusion.
Name the main class of your election client program ElectionClient
Name the main class of your election serverprogram ElectionServer
Use a constant and consistent grading style. I suggest you look at the Coding Conventions page on the CS211 website for guidance and advice.
6. Partners and Other Important Information
As before, you can work in a group of 1-3 people total. You may work in a group different
from your part 1 group if you like.
You may use any group's part 1 programs to do this assignment, or you may use my
solution files if you wish.
7. Submission
You should send your project submission to my email address (ejk16@cornell.edu). Please put all submitted files in a .zip file whose name has the format "proj2_<netid>.zip", where <netid> is the netid of one of your group members. For example, I would submit a file called "proj2_ejk16.zip".
Your zip file should contain the following files (at least):