PS-6

Introduction

As promised, we're going to build a collaborative graphical editor — akin to Google Docs' ability to have multiple simultaneous editors of the same document. In both cases, multiple clients connect to a server, and whatever editing any of them does, the others see. So I can add an ellipse, a friend on another computer can recolor and move it, etc. This code handles multiple objects at a time, and can draw rectangles, line segments, and "freehand" shapes in addition to ellipses.

The basic client/server set-up is much like that of the chat server. Each client editor has a thread for talking to the sketch server, along with a main thread for user interaction (previously, getting console input; now, handling the drawing). The server has a main thread to get the incoming requests to join the shared sketch, along with separate threads for communicating with the clients. The client tells the server about its user's drawing actions. The server then tells all the clients about all the drawing actions of each of them.

architecture.jpg

There is one twist, to make this work nicely. A client doesn't just do the drawing actions on its own. Instead, it requests the server for permission to do an action, and the server then tells all the clients (including the requester) to do it. So rather than actually recoloring a shape, the client tells the server "I'd like to color this shape that color", and the server then tells all the clients to do just that. That way, the server has the one unified, consistent global view of the sketch, and keeps all the clients informed.

Given that the architecture is much the same as with the chat server (and other client/server set-ups), the bulk of the assignment comes down to establishing the message passing protocols between client/server and ensuring that they all maintain and modify a consistent shared view of a common sketch.

Implementation Notes

A scaffold, editor.zip, is provided. It includes a number of files including:

Please take the time to familiarize yourself with these files, and read over the whole assignment carefully regarding how the pieces fit together, before even thinking about coding. Begin by looking at EditorOne. This code is an implementation of a simpler version of the Editor you'll write as part of this assignment.

Add your code to the scaffold, and provide additional classes and methods to finish it off. You can change type signatures for some of the "your code here" methods if you want, and feel free to add more; it's just to give the structure. The code isn't particularly complicated, but there are a lot of moving parts, and you need to be clear on the protocol (request a sketch update to the server and act on a command from the server).

You will need to develop your own classes to maintain sketches (the shapes shared among the editors) and to handle messages between the editors and server.

Some thoughts regarding how to approach the implementation.

Editor

Sketch

Messages

Client-server

Exercises

For this problem set, you are allowed to work with one partner. Note that you do not have to work with a partner, and if you do, you will both be given the same grade; there is no penalty (or bonus). You should weigh whether you will get more out of this assignment working alone or with someone else. If you choose to work with someone else, pick your partner carefully, and make sure it is someone you will be able to coordinate with, work well with, etc. Re-read the course policies.

  1. Finish off the missing pieces in Editor, Rectangle, and Polyline, along with a mechanism for handling the shape list (Sketch). These can be tested by directly modifying things, as in the standalone editor, before thinking about messages.
  2. Devise a set of string-based messages by which the clients and server will communicate drawing actions, along with a mechanism for parsing these messages and invoking the appropriate actions to update the shapes. The methods are up to your design, but should be fairly straightforward reflections of editor commands to add, delete, move, and recolor.
  3. Use the EchoServer to test your classes, before dealing with the actual SketchServer. By using the EchoServer, you essentially have a single-machine drawing program which acts on echoed messages that it sends out and gets back, rather than sending/receiving messages via a SketchServer. This should allow you to focus on the client-side part of this lab and make sure it is working before you try to implement the server-side components.
  4. Now all that is left to implement is the SketchServerCommunicator. There isn't much code to write but you do have to do a few things to handle multiple instances of editors connecting (e.g., telling a client the current state of the world when they first connect, and getting and handling messages from the client). Now hook them up and let them go. Start up a server instance first. Then start an editor. Test on your own machine (set serverIP to "localhost"), and with a friend (give them your IP address or vice versa). Take a screenshot of a collaboratively edited sketch. If you're working independently, you can just have two Editors running on your own machine (i.e., self-collaboration).
  5. Consider possible multi-client issues. What unexpected/undesired behaviors are possible? Can you actually make any of them happen? Where and why do you use synchronized methods; will they handle everything? Write a short (approximately a paragraph) response.

You may obtain extra credit for extending and enhancing the editor. Only do this once you are completely finished with the specified version. Make a different file for the extra credit version, and document what you did and how it works. Some ideas:

Submission Instructions

Submit your completed versions of all the classes, thoroughly documented. Also submit a snapshot of a collaborative client-server drawing session, and a document with your brief dicussion of synchronization issues.

Grading Rubric

Total of 100 points

Correctness (70 points)

5Rectangle
5Polyline
10Event handlers
10Sketch: maintaining shape list, identifying selected shape
10Drawing shapes and partial shapes
5Sending strings between clients and server, using EditorCommunicator and ServerCommunicator
10Composing messages, and decomposing and acting on them
10Run loops in ServerCommunicator and EditorCommunicator (5 each)
5Consistency of sketches across clients and server, including new clients

Structure (10 points)

4Good decomposition of methods
3Proper used of instance and local variables
3Proper use of parameters

Style (10 points)

3Comments for new methods (purpose, parameters, what is returned)
4Good names for methods, variables, parameters
3Layout (blank lines, indentation, no line wraps, etc.)

Testing (10 points)

7Snapshot of a collaborative drawing
3Discussion of multi-client