CS262, Spring 2008, Programming Assignment 1

Internet Banking

Your assignment is to create a simple distributed banking system. The system will consist of two programs. One of these is the service component, and will represent the bank. The bank has a number of accounts; these accounts can be created (with an initial deposit value) and destroyed. In addition, accounts can have money deposited, can have their account balance queried, and can have money withdrawn.

The client program should provide access to the functionality of the bank, allowing accounts to be created and destroyed, account queries to be made, and deposits taken and withdrawals processed. Error conditions are important; trying to create an account which already exists is a bad thing, as is destroying an account that doesn't exist. This is like a real bank, so deposits will always be taken (although not if they are made to a non-existent account); withdrawals will not be allowed if there is insufficient funds in the account. The interface should be command-line based, and allow all (and only) the following commands:

The communication mechanism to use for this assignment is sockets (in particular, java.net.ServerSocket and java.net.Socket). This means that you will need to design a protocol that will allow the right thing to be done when the client makes a call to the server, and for the server to respond to the client. Errors should be reflected in the client program in some way (i.e., you should tell the interactive user why an operation can't be accomplished if it can't). There are lots of mechanisms in Java that allow you to automatically generate a protocol; do not use them (if nothing else, this assignment is designed to make you appreciate such mechanisms).

Don't worry about security; assume that both programs will run with a wide open policy file (policy.all), and that no encryption is needed for the communication. However, there may be multiple clients connected to your service at any one time, so your code needs to be thread-safe, and you need to be able to deal with multiple connections on the service (which means that java.net.ServerSocket.accept() will need to spawn a thread per connection).

All code should be rooted in the package

edu.harvard.cs262

If you want to introduce further packaging, have at it.

The assignment will be marked as complete when I have received (by email) two tarballs from you. The first should include both the source and the binary for the banking service, along with an informal specification of the wire protocol you are using for communication. The second should include the source and binary for the client, and a script to start the client. Your client does not need to deal with network failures, but it should be able to deal with starting up before the service has started up. You get to decide what "deal with" means here. Your service should also be running on one of the class' server machines (cs262-{0,1,2,3}); which machine you run the server on is determined by programming assignment 0. You should have your service listen on the port which is the last five digits of your student ID.

You will successfully complete the assignment when I can start the client, your client connects to your server, and I can beat on the client in any way possible without making either the client or server crash. Oh, and when I make a series of correct commands to the service, I should get the right balance on an account :-).

You should be using at least JDK1.5 (aka J2SE5.0), available for download at a server near you, if you already have JDK1.6 that's fine as well. You may work in pairs on this assignment (in fact, I encourage it); if you do so please indicate both participants in the email that you send to me. You should try to have this done Monday, 2/25.


Jim Waldo