Instant messaging (IM) is a staple of the web and has been around almost since its inception, starting with simple text-based programs like talk and IRC and progressing to today's GUI-based IM clients from Yahoo, Microsoft, AOL, etc. In this project you will design and implement a text-based IM system (both the client and the server). The following characteristics constrain the design space of an IM system:
The purpose of this project is twofold. First,you will learn several Java technologies, including networking (to support connectivity over a network), sockets and I/O (to support real-time, text-based communication), and threads (to support two or more people communicating concurrently). As in project 1, you will have the opportunity to use state machines to specify certain aspects of the system's behavior.
More importantly, you will start learning how to take a set of high-level, informal requirements and iterate through the design, specification, implementation and testing of an end-to-end system.
Implement an IM system in Java with the following properties.
Client. The client is a program that opens a network connection with the IM server at a specified IP address and port number. Once the connection is open, the client program takes input from the user (as text, from the console), and forwards the input to the IM server. The client program also receives text from the server and displays it to the user. If the server terminates the connection, the client program notifies the user that the connection has been terminated, and exits. You do not have to write the client program. A client program that satisfies these requirements already exists on almost all operating systems, called telnet. You can run telnet by opening a command prompt and typing telnet hostname port.
Server. The server is a program that accepts connections from clients. A server should be able to maintain an unlimited number of open client connections, and clients should be able to connect and disconnect as they please.
The server is responsible for managing the state of both clients and conversations.
Conversations. A conversation is an interactive text-exchange session between some number of clients, and is the ultimate purpose of the IM system. The exact nature of a conversation is not specified (although the hints section details a couple possibilities), except to say that it allows clients to send text messages to each other.
On March 6, you will hand in a design document that includes:
You should both commit your design documents to your pair repository and put a hard copy in the LNB box for your section by 5PM.
On March 13 you need to hand in:
Your code, test suite, and reflections should be committed to your pair repository by 5PM. You should also put a hard copy of your reflections in the LNB box for your section.
All commentary and diagrams should be in plain text or PDF and saved at the top level of your project directory. Each PDF or text file must contain an appropriate title describing it, along with the Athena usernames of you and your partner. Make sure your files have the appropriate extension (.pdf or .txt).
90% of your grade will be allotted to the design and implementation, and 10% to the design extensions. Of the 90%, 30% will be allotted to the command grammar and state machine model, 40% to the code (half for structure and half for correctness), and 20% to test cases.
Or is a conversation more like a phone call, where a person "dials" another person? In that case, can the receiving party deny the conversation?
However you define a conversation, remember to keep it simple for your first iteration. You can always extend your program with interesting ideas if you have time left.
Working with telnet. As mentioned above, you already have an implementation of the client, namely, telnet. Play with it and learn its limitations. This should provide some pointers for your design. However, make sure your design could be easily extended to work with other clients that provide richer functionality (GUI, security, etc.) than telnet does.
Handling multiple clients. Since instant messaging is useless without at least two people, your server must be able to handle multiple clients connected at the same time. The Friendly server you'll develop in the lab gives you some starting code, but note that Friendly doesn't need its clients to interact or share any state. Your server will certainly need to do that. One reasonable design approach follows the Friendly model (using one thread for reading input from each client) but adds a central state machine representing the state of the server (using one more thread, to which each of the client threads pass messages through a shared queue).
Designing for safe concurrency. In general, making an argument that an implementation is free of concurrency bugs (like race conditions and deadlocks) is very difficult and error-prone. The best strategy therefore is to design your program to allow a very simple argument, by limiting your use of concurrency and especially avoiding shared state wherever possible. For example, one approach is to use concurrency only for reading sockets, and to make the rest of the design single-threaded.
Designing for testability. To make it possible to write unit tests without having to open socket connections and parse streams of responses, you should design your state machine(s) in such a way that they can be driven directly by a unit test -- either by calling methods, or by putting messages into a queue read by the state machine's thread.