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.
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 pen can be in one of two modes, "draw a line", or "draw a
dot". In "draw a line" mode, if the mouse is dragged (moved with the
button down), a line is drawn between the successive points of the
mouse events. In "draw a dot" mode, the mouse behaves as it does in
SimplePaint, drawing a small circle at each mouse event point. A mouse
drag is always preceeded by a mouse pressed event. This mouse press
will be used as the starting point for the first line segment in "draw
a line" mode. Unlike SimplePaint, your program should draw a dot if
the mouse is pressed and then released without being moved (in either
mode).
- The width of the pen can be adjusted (just as in SimplePaintMenu).
- The color of the pen can be changed by selecting a color from a
menu. One of the colors should be white, allowing for "erasing".
- The entire canvas can be erased using a menu selection.
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.
- DRAW_TO - followed by two integer values representing the x and y
coordinates of the point at which to draw. A DRAW_TO command should be
generated for each mouse drag event.
- PEN_DOWN - followed by two integer values representing the x and y
coordinates of the point where the mouse was pressed.
- PEN_UP - generated when the mouse is released.
- PEN_SIZE - followed by a byte indicating the diameter of the pen
tip.
- PEN_COLOR - followed by three bytes representing the Red, Green,
and Blue values of the new pen color.
- CLEAR - indicating the canvas should be cleared (erased).
- LINE_MODE - the pen is in "draw a line" mode.
- POINT_MODE - the pen is in "draw points" mode.
- QUIT - what a well behaved client sends before exiting.
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.
- ImageReaderWriter.java contains
the two methods you can use to read and write the images to/from a stream.
- ImageTest.java lets you see how to
read an image from a stream.
- ImageGen.java generates an image
stored in a file, suitable for reading by ImageTest. It also shows how
you write the Image.
[Homepage] |
[General Lab Info] |
[TA's & Tutors] |
[FAQ's] |
[Homework] |
[Excellent Programs] |
[Exams]