Extras: Networking

Chat Server

This example is intended to tie together a lot of concepts. In this example, you will use Exceptions, Collections, IO concepts, Threads with synchronization, and Networking concepts. Here are the modules to this application:

A picture of the overall design can be seen in the following Image:

Making your ChatClient Into an Applet

If you want to make your Chat Client into an Applet, you might find the following useful:
chatRoom.html
ChatClientApplet.java

This applet assumes that your server runs on gettysburg. Make sure that the port number for your Server matches the port number found in the chatRoom.html param statement. Also I would highly recommend that you compile ChatClientApplet.java and all of the classes it uses with JDK1.1.8. Current browsers don't support JDK1.2.2 unless you install a large plugin. If you set your path to T:\faculty\chasselbach\jdk\bin, you will get JDK1.1.8.

When you start up your chat server on gettysburg, use port 9xx0 for your port number where xx contains the last 2 digits of your gettysburg login.


Datagram programming

Point to Point Quote Server

Source: QuoteServer.java
one-liners.txt
Source: QuoteClient.java

Multi-cast Quote Server

Source: MulticastServer.java
Source: MulticastClient.java


Exercise

Modify the ChatServer and the ChatClient to add Chat Names. From a user's perspective, he will be prompted for his Chat Name before his session starts. This name will be sent across to the Chat Server. From this point on, messages showing up will always have the sender's name associated with it. For example:


Suppose that I connect to the chat room and say my name is Clem. Previously, Sam and George have also connected and entered their names. Clem's screen should look something like:

Sam says: I like this chat room ... everyone is so friendly
George says: At least most of the time
You say: I agree

This same conversation shows up on George's screen as:

Sam says: I like this chat room ... everyone is so friendly
You say: At least most of the time
Clem says: I agree


By the way, if you are a chat room enthusiast and want to do more, feel free to be creative as long as you meet the minimum requirement specified above.

Hints:

You can automatically send the first packet to the server with the user's name. I would add a new variable to the Chat class to hold the client's name. You might want to check for uniqueness of the name. If you find that name already used, you might want to append a number make the new name unique. When you find yourself changing a name to make it unique, I would send one message to the user who sent the duplicate name indicating that his name was altered to make it unique. You will probably have to add a new function to the ChatArea class to do this.

Optional extra work:

Note that if a Client goes away, that we don't currently reuse the child thread spot. You might want to rectify this deficiency.


Last Modified: November 15, 2002 0:12 AM