Project 3 - P2P Distributed Messaging
Part 1 - Due - Monday, April 5, 2004
Part 2 - Due - Wednesday, April 14, 2004
The goal of this assignment is to give you an understanding of
peer-to-peer computing by having you write a peer-to-peer
messaging program. For your program, you will implement a
peer which can send and receive messages (i.e., act as both
a client and a server). To test your program, you will run it on
two or more iPAQs.
This assignment may be done in groups of 2. If you wish to work
in a group of 3, you must get approval from me first. Also,
recall that your working program must be tested on the iPAQs.
When you are ready to test, you can check out iPAQs, two at a
time, from the media desk at the library. Please remember that
everyone will be using the same set of iPAQs. This means that
only three groups may be testing at any one time. Also, the iPAQS
will only be available during the hours that the library is open.
Please plan accordingly. Not having access to the iPAQs will not
be a valid execuse for submitting the assignment late.
Functionality
A peer should consist of at least the following pieces:
- Receiver: The Receiver piece of the peer should be
capable of (1) listening (on a socket) for a connection from
another peer (the sending peer), (2) accepting the connection,
and (3) receiving messages sent from the sending peer and
displaying those messages .
- Sender: The Sender piece of the peer should be
capable of (1) opening a socket to another peer (the receiving
peer) and (2) sending a message to that receiving peer. You can
assume that the Sender has a statically configured list of IP
addresses which represent all of the peers it knows about. You
can hard-code in this information. When the Sender is called
upon to send a message, it will send it to all of the IP
addresses on its hard-coded list.
- Driver: The Driver piece of the peer should be
capable of (1) creating the Receiver and Sender pieces of the
peer and (2) creating or implementing the testing portion of the program.
Using Threads
A peer should be able to receive messages and send messages at the
same time. To accomplish this, you will need to use
Threads. Your Receiver and Sender should each be
implemented as a separate Thread. To accomplish this, your
Receiver and Sender classes should implement the interface
Runnable. For example:
public class Sender implements Runnable {
Any class which implements the interface Runnable must also
implement a method run. The header for this method should
look as follows:
public void run()
Finally, to begin execution of the Thread, you must create a new
instance of the class, create a new instance of a Thread by
invoking the Thread constructor and passing it the instance of the
class you just created, and call the start method of the Thread
object. For example, if you had a class MyThread which
implemented the Runnable interface, you would start the thread
with the following code:
MyThread mt = new MyThread(); //Note, your constructor may take a
parameter
Thread t = new Thread(mt);
t.start();
Testing
To test your program, you need to start at least two peers and
each should successfully send messages to the other and receive
messages from the other. A simple way to perform testing is to
have the Driver periodically ask the Sender to send a
preconfigured "message of the day" to all of the other peers it
knows about. For example, you might have the Driver do this every
5 seconds. The question is, how do you have your program do
something every 5 seconds? The answer is, you tell your program
to "sleep" for 5 seconds, then wake up and do something. The
following piece of code shows you how to accomplish this. This
piece of code would be a part of your Driver:
//do this forever
while(true) {
//put the Driver to sleep for 5 seconds (5000 milliseconds)
Thread.sleep(5000);
//tell the Sender to send a message
//this piece of the algorithm will vary depending on the
//rest of your code
}
If you use this strategy for testing, you will be elgible for an
A- (maximum of 90%) on the project.
For full credit (maximum of 100%), you must implement a User
Interface similar to the interface you implemented for Project 1.
At minimum, your interface should consist of a button and a text
area. Your Driver class will instantiate the User Interface and
pass it all relevant information. When the button is pressed, the
User Interface should notify the Sender that a message should be
sent. When a message is received from another peer, the Receiver
should notify the User Interface that a new message should be
displayed in the text area. You can assume that each peer has a
preconfigured "message of that day" that it sends whenever the
button is pushed.
You have three extra credit options:
- Create your interface such that it will allow the user to
enter the message to be sent. The user should be able to type the
message and press the button. The interface will retrieve the
message to be sent and send the same message to all peers on the
Sender's hard-coded list. (worth 5%)
- Define and implement a protocol for communication between
peers. (worth 5%)
- Instead of having a hard-coded list of peers which your
Sender keeps track of, configure this information dynamically.
You could do this by creating a file and having your Sender read
this information in from the configuration file or by passing in
IP addresses as command line arguments. (worth 5%)
Part 1 Turnin
For Part 1, you need to turn in:
- A full specification of your design. This should include
(in writing) a drawing which shows the interaction between peers
and a description of each piece of your peer and the
functionality of that piece.
- A code skeleton which includes all Java classes and all methods
you plan to implement for those classes. For each method, you
should describe the type and functionality of the parameters
(inputs) and return values (outputs).
The class period on April 5 will be devoted to discussion of the
Project. We will discuss any general design and implementation
questions as a group for the first few minutes of class. For the
remainder of the class period, I will meet with each group
individually to make sure you are progressing and ensure that I
provide you with any help that you need. Bring a printout of both
your specification and your code skeleton to class on April 5.
Part 2 Turnin
For Part 2, you need to turn in:
- Your completed Java code.
- A revised, written specification of your design which
describes any changes you made to your design in part 1 and
justifies why the change was necessary.
For 5% extra credit, make an appointment with me to demonstrate
your working program. You must complete your demonstration
on or before April 14.
Sami Rollins