Homework 6 - Distributed Computing


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Homework] | [Excellent Programs] | [Exams]

Reading: Chapter 13

Due: At 8:00am, Wednesday March 14, 2001, submit is turned off automatically. Work turned in after that time will not be accepted for grading.

NEW Be sure and read the grading guidelines for this assignment. I believe I got a bit carried away. If you fully implement the specification below you will get a 7 (remember 5 is full credit). I have tried to provide a detailed guideline about what part of this specification must be working in order to receive "full credit" (a five).

Program Description

For this assignment you must create a multiperson drawing program. The program will allow any number of people, sitting a different computers, to collaboratively create a computer drawing.

The basic drawing program will be similar in functionality to SimplePaintMenu from Chapter 9. The drawing program must support the following operations.

The big difference is that the program can be used to connect to another persons drawing program, so that both users see the same drawing, and draw on the same canvas. All drawing operations of one individual all reflected on the drawing of the other. In fact, any number of people can be drawing on the same canvas at once.

The program will operate in two modes, server mode, and client mode. In server mode the program starts up and begins listening for connections on a port. The port number is specified on the command line. In addition to listening for connections, the program presents the user with a blank canvas and drawing can begin. If no one else connects to the server, then it acts just like an enhanced SimplePaint.

If another user connects, using the program in client mode, then the server passes its drawing operations to the client and the client passes its drawing operations to the server. In addition, when the client starts up, the server sends the client the current state of the drawing.

If two or more clients connect to the server, then the server must send its drawing operations to all clients. Furthermore, the server must also send any drawing operations it receives from any client to all of the clients, so that all clients and the server always see the same drawing.

Clients can come and go, and the server should continue to operate.

The Simple Paint Protocol

The Simple Paint Protocol (SPP) is a made up protocol just for this assignment. In order to allow your program to communicate with another student's program, all programs should use SPP for communication between the Paint Server and the Paint Clients.

When the server receives a connection from the client, it uses an ObjectOutputStream to send the image. (I will provide you code to do this - I was dismayed to discover that java.awt.Image is not Serializable).

Likewise, when the client connects to the server, it expects to first receive the data needed to construct the initial image (I will provide this code also).

After that the following paint commands can be sent, in any order, and as often as necessary. The protocol is asymetric in that the server preceeds each command with an integer id identifying who generated the command. That is, when the server sends drawing commands to clients it first sends an integer and then one of the commands below. When the client sends drawing commands to the server it sends only the drawing command below (no preceeding integer). This integer id is used by the clients to keep track of which pen is being used for drawing (see Multiple Pens below). Each command is one byte, followed by zero or more bytes, depending upon the command. The values are taken from the interface DrawingConstants, created for this exercise.

Multiple Pens

Although there is only one shared canvas or drawing, each user has their own pen with its own settings. For example, one user could be drawing with a wide red pen in "draw a line" mode, while another was drawing with narrow green pen in "draw points" mode.

Getting Started

For now, you can begin modifying SimplePaintMenu to support the additional drawing features. In addition, you can begin to think about how the two programs will interact. I suggest getting a class diagram of the SimplePaintMenu (I started with the one I did in class where the canvas had a fillOval() method). Then think about how the classes that listen to the mouse motion events from the canvas, and the pen adjusting operations. You can create classes that duplicate the operations of those two classes, but they do their work in response to commands from a remote computer instead of local mouse events or pen adjustment calls.

I have solved the image reading/writing problem. Here are three you can use.


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Homework] | [Excellent Programs] | [Exams]