Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(java) The server is multi-threaded. It maintains a list (a ArrayList will work well) of all the active connections. It will listen on a port

(java) The server is multi-threaded. It maintains a list (a ArrayList will work well) of all the active connections. It will listen on a port for a new connection. You have the authority to choose the port number and design appropriate protocol for client-server communication. When one comes in, it spawns a thread to handle the connection, and the main thread resumes listening. The spawned thread sends out a message asking for an ID name on the socket. When the client replies, the connection information is added to the master list of chat room occupants (so there is a shared ArrayList of PrintWriter references). From that point on, anything that is typed by the client is relayed to all chat room occupants (including the client), with the ID identifying the client. Of course if null is read from the client, or the special value LOGOUT then the client has disconnected and you should remove the connection from the shared ArrayList and then exit the thread gracefully (i.e. stop the infinite loop in the run method). Dont worry too much about error checking. However, you will need to be careful to synchronize access to the array list using locks, since otherwise you might delete an entry while another thread is trying to broadcast to everyone, potentially resulting in an out-ofbounds ArrayList access or worse. You can test the server by starting it and connecting via several telnet windows. (You can turn the echo on for the telnet windows to see what you are typing.) Broadcast a message when the client first joins the chatroom, and then broadcast a message when the client leaves the chatroom (in the finally block, after adjusting the ArrayList, but immediately prior to terminating the run method).

Bonus Part You should be able to have multiple chat rooms simultaneously. Also, the server should make sure that there are no two clients with the same ID name in a chatroom at any given time. If a client wants to join with an ID acquired by another chatroom occupant, the server has to notify the client to choose a different ID.

2. Submissions You need to submit a .zip file compressing the following files: Java source file(s) of your program (.java files) Readme.txt file specifying every command of the protocol used for client-server communication.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions