You will be designing a chat room service.
Your program will consist of three main parts:
- A GUI Controller – this will have instructions, and buttons to start the server, to start each client, and to exit.
- Client – The Chat application for each user. Each client will run in its own thread. Start this class after the Server is running.
- Server – Manages the clients, checking their screen names and echo-printing their messages to the other clients. Start this class before the client.
Step1
Operation (what the user sees):
When the application starts, the user is presented with a window that has a list of instructions and three buttons: “Start Server”, “Start Client”, and “Exit”.
The user starts the server first. If they attempt to start a client before a server, or to start more than one server, an error message is given.
Then the user starts a client. The user is asked for a screen name. If the name is already in use in this session an error message is given the user is re-asked for a screen name, or if the user selects “Cancel”, the user is re-asked for a screen name. The user can start multiple clients.
When a user successfully enters a screen name, a window is shown where the user can type in a message. When the user enters a message, it is rebroadcast to all users.
Specifications (what the programmer does):
- Create a GUI Controller: this will have instructions, and buttons to start the server, to start each client, and to exit.
- Instructions will be several labels
- Start Server Button:
- This button will have a mnemonic and a tooltip.
- When this button is selected, create a new ChatServerExec.
- Then call the ChatServerExec.startServer method with the port number as an argument if the server has not yet been created.
- The GUI controller will maintain a sentinel that specifies whether or not the server has been started yet, and display a JOptionPane message if it has.
- Start Client Button:
- This button will have a mnemonic and a tooltip.
- Each time the “Start Client” button is selected in the GUI, create a new ChatClientExec.
- Then call the ChatClientExec.startClient method with the port number as an argument
- Exit Button:
- This button will have a mnemonic and a tooltip.
- When selected, the server and any clients, along with the controller GUI, will close.
- Client – The Chat application for each user. The client will consist of an executive (ChatClientExec) and ChatClient classes.
- Start ChatClientExec from the GUI after the Server is running.
- ChatClientExec will create a new ChatClient and run it in its own thread.
- The ChatClient process will create a new Stage, which will produce a separate GUI for each client.
- The user will be asked to enter a screen name
- When the screen name is accepted, the client’s chat textbox will be enabled. When the user types into the textbox, the client will transmit the message to the server.
- When the client receives messages from the server, it will be displayed in the client’s textarea.
- Server – Manages the clients.
- Maintain a list of screen names in use in this session and check new names for duplication.
- Maintain a list of PrintWriter objects, and iterate through them to echo-print clients’ messages.
- Start this class before the client.
- Assumptions:
- It is assumed that the GUI, the server, and clients will be run on the same computer.
- It is assumed that synchronization of objects with locks or conditions will not be needed.
- Application Protocol. The Chat Protocol is as follows. (Bold font indicates strings sent between server and clients)
Condition | Server Action | Client Action |
Client starts, server accepts client | Sends “SUBMITNAME” | Receives “SUBMITNAME” and asks user for screen name |
Client has received “SUBMITNAME” | Server blocks waiting for input | Client sends screen name |
Client has sent screen name | Receives client screen name, checks for duplicates, sends “NAMEACCEPTED“ | Client blocks waiting for input |
Server has sent “NAMEACCEPTED” | Server blocks waiting for input | Receives “NAMEACCEPTED“, sets message text field to “editable” |
Client has received “NAMEACCEPTED” | Server blocks waiting for input | Client types a message in text field, sends message |
Client has sent message | Receives client message, sends “MESSAGE name: message” to all clients | Client blocks waiting for input |
Server has sent message to all clients | Server blocks waiting for input | Client receives “MESSAGE name: message” and prints to text area. |
Deliverables:
Java files – The src folder with your client and server and test (.java) files
Javadoc files – The doc folder with your javadoc for student generated files
UML Class Diagram (an image, not the proprietary format, must be a .jpg or .pdf)
Deliverable format: The above deliverables will be packaged as follows. Two compressed files in the following formats:
LastNameFirstName_AssignmentX_Complete.zip [a compressed file containing the
following]
UML.jpg
Assignment 7 Checklist (filled in with YES or NO or ?)
doc [a directory] please include the entire doc folder
generated files
file1.html (example)
file2.html (example)
src [a directory] contains your client and server (.java) files. Include all
files that are needed to run your assignment, including those given to you
File1.java (example)
File2.java (example)
File_Test.java (example)
LastNameFirstName_AssignmentX_Moss.zip [a compressed file containing only the
following]
contains .java file which includes student generated client and server (.java) files – NO FOLDERS!!
File1.java (example)
File2.java (example)
Reviews
There are no reviews yet.