A Simple Chat Application


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:

The files needed are: Regarding names, Talker and ServerTalker seem backward.  I am calling it ServerTalker because it "talks" to the server.  Bad choice.  I know.

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:


Compile and Deploy Class Files

    Compile the Java source files

    Make sure that the deployment directory $HOME/class and the development directory $HOME/java/examples/chat are each accessible through the local CLASSPATH on the development machine, before attempting to compile.

    To compile the Java source files, run the javac command as follows:

    For an explanation of javac options, please refer to the Solaris javac manual page or the  Win32 javac manual page.

    Use rmic to generate skeletons and/or stubs

    The rmic command takes one or more class names as an argument and produces class files of the form MyImpl_Skel.class and MyImpl_Stub.class.

    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 and client

    Create the HTML file

      <html>
      <applet code="examples.chat.ChatImpl.class"
         width=800
         height=400
      >
      </applet>
      </html>

Start the server

  1. For Solaris:

  2.  

     

    java  examples.chat.ChatServerImpl &
     

  3. For Windows:

  4.  

     

    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):
appletiewer ChatApplet.html
Good luck!

Enhancements