Out: Wednesday, March 12, 2008
Due: Thursday, March 27, 2008
Sunday, March 30, 2008
Each client will connect to one server via a durable TCP connection. Each client will have a handle, which is assumed to be globally unique. The client will send to the server a sequence of text lines. The client does not echo messages locally. Instead, it sends messages entered at the client on to the server and displays them only when the server sends them back. This allows the server(s) to control the order in which all messages are displayed at each client.
There will be some number of servers, all connected via a mesh network: each server will be connected directly to all other servers. Each server will transmit each message, along with the handle of the client who sent it, to its live clients and to all the other servers.
Your fundamental task is to coordinate the servers so that all the clients on all the servers see all the messages in the same order.
Thus if client1 and client2 both transmit the sequence of lines
This is message one. This is message two. This is message three. This is message four. This is message five.then all clients should see the same sequence of messages, which will be something like
client1: This is message one. client1: This is message two. client2: This is message one. client2: This is message two. client1: This is message three. client2: This is message three. client1: This is message four. client2: This is message four. client1: This is message five. client2: This is message five.Observe that the messages from client1 and client2 are interleaved in an arbitrary order, but the messages from each client appear in order.
Each client will take three command-line parameters: a hostname to connect to (given as a resolvable domain name or an IP address), a port to connect to, and a handle (assumed to be unique in the system). We provide a sample client program that takes three command-line parameters: a hostname and port of a server to connect to, and a name or handle to use during the chat. The client supports Emacs line editing commands through the GNU readline library, so you should find it easy to use. The client communicates with its server over a TCP connection using a very simple protocol. You don't need to modify the client for this lab, although you might find it useful to automate the client for testing purposes.
Your server will take a set of command-line arguments including its ID number (which is guaranteed to be unique in the system), a port number to use for network communication, and a list of hostnames and ports for the other servers in the network. It will then forward messages from any clients connected to it to any other directly-connected clients and all other servers. Similarly, it should forward any messages received from other servers to its own clients.
You are responsible for the following requirements:
You are allowed to assume the following (non-realistic) things:
% ./chat-server 1 2255 localhost 2256where 1 is the globally unique ID of this server, and 2225 is the port you want it to listen on. localhost and 2256 are the hostname and port of another server in the network. You can have as many hostname:port pairs as you'd like.
For the sake of discussion, start another server in a separate window with a similar command:
% ./chat-server 2 2256 localhost 2255You can connect to a server with the provided client from another window in the following fashion:
% ./chat-client localhost 2255 Client1In a fourth window, you should start up another client with a slightly different command line:
% ./chat-client localhost 2255 Client2Any messages typed at either client should appear at both. You can exit from the provided client by typing CTRL-D by itself at the prompt. If, on the other hand, you connect the second client to the other server, with the following command,
% ./chat-client localhost 2256 Client2you'll see that the messages are not passed between the servers. For your assignment, you'll need to fix that up. An obvious first step is to simply have each server send any messages from its clients to all other servers. The hard part is making sure they're displayed in the same order at all clients.
First, create a file, say messages.txt, such as the one below:
This is message one. This is message two. This is message three. This is message four. This is message five.You can then use this file to drive two clients simultaneously, like so:
./chat-client -i localhost 2255 bot1 < messages.txt > output1.txt &; \ ./chat-client -i localhost 2255 bot2 < messages.txt > output2.txt &This will cause two clients, called 'bot1' and 'bot2', to simultaneously connect to the server at localhost:2255 and send the set of messages contained in messages.txt. The output of each will go into files output1.txt and output2.txt, respectively. Notice that I've arranged things so that a single shell command starts both clients in the background.
If you try this, you'll see that the order in output1.txt and output2.txt is the same. Once you can issue the same command, but connect the clients to different servers, and the order still comes out the same, you're well on your way. Keep in mind that we'll be testing with a lot more than two servers, and killing some off in the middle.
Your deliverables should include a description of your program and its parts. This should include a description of the algorithm and documentation of the code (eg, which modules implement which portions of the algorithm). The documentation and comments in your code should make it possible for a reader who knows the algorithm to read your code easily.
Submit your package as a gzipped tar file. You can build this by doing something like
mkdir mp4 cp {all files} mp4 tar cvf mp4.tar mp4 gzip mp4.tar mv mp4.tar.gz yourname-mp4.tar.gzSend yourname-mp4.tar.gz to xindong@ccs.neu.edu.
Last modified: Mon Mar 17 14:21:09 EDT 2008