CIT 597 Assignment 4: Very Simple Chat Program
Fall 2004, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Write a simple chat program, using Swing, which you can use to converse with one other user. The "other user" may be a separate version of the program running on the same computer.

Details:

Write one program that acts as both a client and a server. For examples, see ReverseClient.java and ReverseServer.java. ReverseClient expects an IP address as its single parameter to main; the parameter may be localhost to say "this computer".

As a server, it has to start listening on a specific port (use port 8122). As a client, it has to initiate communications on the port that the server is listening to. For communication to occur, the server must start up before the client.

When your program starts up, it must decide whether to start as a client or as a server; one possible way to accomplish this is to ask the user. A better way would be to send a message and see if it gets a response within a couple of seconds--I haven't tried this, but the connect(SocketAddress endpoint, int timeout) method in java.net.Socket should work.

Your program should ask for the user's name when it first starts up. This will be used as a message prefix.

The GUI should have (at least) these two text areas:

You can use other GUI elements as you choose, so long as your interface is simple and obvious.

Your GUI should be in Swing. If you have only used the AWT, not Swing, I have a program and some examples that should greatly ease the transition for you. Download SwingExamples.zip and unzip it in a directory of your choice. This will unzip into two files, SwingExamples.jar and SwingExamples.java. You must keep these files together in the same directory. Run the program by double-clicking on SwingExamples.jar.

An additional requirement is that either user can send a message at any time. This means that your program cannot block while waiting to receive a message. You will need to listen to the user and send messages in one Thread, listen to the port and receive messages in another Thread, and you will probably need to synchronize some GUI elements.

Due date:

Before midnight, Tuesday October 26.