6.096 Fall 1996
Introduction to Interactive Programming

Laboratory 7: Client/Server


This assignment emphasizes the following topics

You should read through this entire assignment and complete the Lab preparation section before lab on Monday. You may also wish to see the email message about this assignment sent last week.




A writeup of the finger exercises should always be turned in along with your completed laboratory. You may do this together with your classmates. You need not complete the finger exercises before laboratory.

The lab preparation work should be completed before you come to lab on Monday.

A. Finger exercises

Network tradeoffs

Pick two of the following networked applications and sketch (using between a paragraph and a page for each) a design for the distribution of their functionality. You should not try to describe the actual implementation of the system; instead, you should brainstorm about the constraints imposed by the problem and the network techniques that would facilitate its solution.

  1. a network of bank ATM machines
  2. zephyr
  3. web browsing
  4. phone call
  5. cable tv (and pay-per-view?)
  6. airline reservations

In particular:

  1. What constraints must your design meet?
  2. What operations does each of the clients support?
  3. What (if any) network operations does each client operation invoke?
  4. What functionality does the server support?
  5. For each of the networked applications, give at least one example transaction, describing which computations occur on which computers and what resources (where) are accessed.
  6. How well does your design meet the constraints you specified above?

B. Lab Preparation

For this assignment, you are going to build a generic server, a generic client, and some specialized client code. You should plan to build a generic client yourself, though you may design it together with other students. You may use either a server that you design and build, one that we provide, or one built by one of your classmates.  (You should specify which you use(d) in your writeup.) You may also extend the basic client, either by yourself or together with a group of collaborators.

Building a Client

In class, we discussed the architecture of a basic client/server application and its Java implementation. Your first job is to implement one of these generic clients. It should support a public void send( String ) method that writes its argument to its socket's outputStream. It should also read strings from its socket's inputStream and call the public void handleString( String ) method of its StringHandler. (You may find it convenient to make your client a StringHandler and let it default to calling its own handleString method.)

You should build a version of the client that implements this basic functionality. You may wish to make use of the following:

We will provide you with the code for a server to test your client with as well as a StringHandler that provides an interface to your client's send method. Details on these will be available at lab; you should only need to be able to construct a client with a StringHandler as a parameter and to supply a send method.

Writing a Client Application

Once your basic client works, you should hook it up to your scribble application, making a shared whiteboard.

In order to prepare for making the transition from a one-user Whiteboard to a networked one, you should answer the following questions (and bring the answers to lab):

Writing a Server (Optional)

After your basic client works, you may optionally wish to design a compatible server. This server should accept multiple connections and handle inputs from each by sending the String received to all of the other connected clients (but not back to the client from which the String came).

You will probably want to use java.util.Vector and java.util.Enumeration to handle multiple client connections. You may also want to use the ServerDialog class that we've provided.

Development Plan

The final stage of pre-lab preparation is to write up a step-by-step description of your incremental development plan.

In particular: What is the minimum self-contained (i.e., testable) functionality that you can implement? How will you test it? What can you add to make a slightly more complex and still fully testable version? How would you test this? Continue listing added features and tests until you scale up to your complete design. This technique, incremental refinement, is an extremely useful and practical way to write code. You may want to read through the suggestions in the In the Lab section, below.


What to Bring to Lab

When you arrive at lab, you should have answers to the questions in the lab preparation a copy of your code design and development plan (on-line or on paper) ready so that we can check you into lab.

In the Lab

In lab, you should write and test the code that you designed.

As always, you should implement your code in simple, testable stages, building on your code only as each stage works robustly. In this case, it should be as simple as following your development plan.

Additional detail, as promised:

  1. Steps you may want to take
  2. Documentation
  3. Running the Demo

Steps you may want to take:

  1. Look at the (new) documentation.
  2. Decide whether you're going to write a client first or to connect your scribble to our client first. (The pre-lab above suggests the second, but you may not have time to do both today.) If you are going to connect the scribble to our client, skip the next step.
  3. Write your client code. You can test it with our server (see running the server, below) and even with one or more of our clients (using ClientTester or ClientMonitor).
  4. Write code to connect the client to the scribbler. This code will presumably extend ScribbleData and implement StringHandler. Your main function will need to set up the classes appropriately. Make sure that something also starts up a client!
    1. You will need to start the server running before you can test your code.
    2. You can monitor the activity of your networked whiteboard by running a ClientMonitor.
    3. If you are using Line's pack and extract methods, you can also run your Whiteboard with one of ours. Start up our demo, then connect to the same server.
  5. If you want to write a server, you can test it with our client.

There's now lots of javadoc. See especially:

To run the demo, first start up the server:

java cs101.util.RunServer &

(You may actually want to do this in its own xterm, since it will report on its activity regularly!) Then, start up one or more scribblers by typing

java SharedWhiteboardDemo &

You can run these on any machine, but they must be connected to the hostname and port where the server is running. After you supply the machine name and port number, you should see some messages indicating that the client is connecting to the server and that it is starting its read loop.

Before you leave

Before you leave lab, you will need to have your work checked off by a course staff member.

At a minimum, you should expect to demonstrate a client application connecting to a server and communicating with it. This can be a simple string-based interface, and you may connect to (an instance of) the server that we provide.

If you built a server, you should demonstrate your client connecting with it and/or let us connect to your server.

If you interfaced applications to either the client or the server, you should be prepared to demonstrate these.

You should be prepared to answer questions about all of the code that you implemented as well as the ways in which this code made use of the pre-defined interfaces.

If your code does not behave as expected, you should be prepared to explain why or to describe what you have done to try to figure out why.

It is always more important that you write clean, modular, well-documented and easy-to-understand code than that you go on to advanced features.

Post-Lab, AKA What To Turn In

Your completed assignment should include:

You should do your writeup individually.

Lab assignments are due on Thursdays at the beginning of class. They may, of course, be turned in earlier.

[Course Home Page] [Lecture Notes Index] [Laboratory Index]

This course is a part of Lynn Andrea Stein's Rethinking CS101 project at the MIT AI Lab and the Department of Electrical Engineering and Computer Science at the Massachusetts Institute of Technology.

Lynn Andrea Stein 6.096-staff@ai.mit.edu

Last modified: Mon Nov 18 12:46:16 1996