CPTS 253 spring 2000

Assignment #6 Chat System

 

Date Assigned: April 21, 2000

Date Due: May 2, 2000

 

Overview: For this final assignment, you are to write a chat system, which follows classical client/server model. The server must be able to handle multiple clients so that a number of people can enjoy chatting all together at the same time.

For the client side, you need to provide appropriate user interface for both typing and reading messages. The way this chat system works is quite simple. Whatever a user types in (using user interface) is sent to the server and the server broadcasts it to all the other chat client applications. As you may easily figure out, this assignment will include swing, io, network and multithreading.

 

Requirements/Guideline: Like any other client/server model based application, you need to write two separate programs for client and the server respectively.

 

Server side:

·        Your chat server should implement Runnable interface. In other words, let a thread keep waiting (or listening) for any connection request.

·        Use ServerSocket class as a server side socket and give it an appropriate port number of your choice. (eg. 9999)

·        You have to provide a distinct handler for each client. Obviously this handler should extend Thread.

 

Client side:

·        Just like the server, your chat client should implement Runnable interface too.  To be more specific, let a thread keep watching its input stream for any incoming message.

·        Use Socket class as a client side socket.

·        Use Swing package to implement user interface.

·        Give a unique nickname for each client so that user can see which message comes from whom.

·        Each client (or user) should be notified whenever a new user enters/exits the chat room. In other words, when a new client is connected to the server or disconnected from the server, all other clients that are connected should be informed.

 

 

 

Hint: Before starting this assignment, you should have a clean big picture of the whole system. The following questions may be helpful for you to visualize the problem.

 

Server side:

·        What is the primary job of the server?

·        Whenever new socket connection is opened for a client (by accept), the server spawns a thread as a client handler. Does the server need to maintain the list of handler threads?

·        When a message arrives from a client, how each client handler thread can broadcast the message to all other clients?

 

 

Client side:

·        How a client can handle incoming/outgoing messages at the same time?

·        Or put it in somewhat detail, how to update chat room messages and how to send the message that a user type in?