This is a simple chat application. The basic idea is to have several client applets who chat with each other. That is, what they type in their TextFields appears on every client's TextArea---a chat session. To do this, each client must first register with a server (an act that is posted to all current clients). When a client contributes a comment, it is sent to the server, who forwards the message to each of the clients.
This basic logic could, for example, be used to implement a collaborative "white board" application.
Client operations include:
Everything is in packages. The NameDialog class, following the author's intentions, is put in examples.util; all other classes are put in examples.chat. I have a similar structure for the source files. That is, I have directories named:
To compile the Java source files, run the javac command as follows:
javac -d $HOME/class *.java
For our example, to create the stub and skeleton for the HelloImpl remote object implementation, run rmic like this:
rmic -d $HOME/class examples.chat.ChatImpl examples.chat.ChatServerImpl
Start the server
- For Solaris:
java examples.chat.ChatServerImpl &
- For Windows:
java examples.chat.ChatServerImpl
Run the client
Once the server is running, the client can be launched as follows (while in $HOME/class/examples/chat):Good luck!
appletiewer ChatApplet.html
private void readObject( ObjectInputStream in ) throws IOException,
ClassNotFoundException
{
sender = in.readUTF();
message = in.readUTF();
}