Create a chat server that can connect to clients. Using Java, you are required to create Server and Client programs. The main scope of each program should be as follows.
The Server program should have the following features:
Listen for new connections from clients.
Handle connections from multiple clients
Respond to client requests.
Broadcast chat messages to all clients.
The Client program should have the following features:
Send new connections to a server.
Accept user input and handle sending to the server.
Handle responses from the server
Along with the features above, the following features can be also implemented.
A client can ask how long the server was running and receive the correct response.
A client can ask the server how long the client has been in the chat room for and receive the correct response.
A client can ask what the servers IP Address is and receive the correct response.
A client can ask the server how many clients in total are currently connected to the chat room and receive the correct response.
A client can ask the server for a list of request commands that can be sent and receive the correct response.
The broadcasting of messages from each client should be handled by the server.
After connecting to the server, the client is asked for a username by the server.
The client should only be able to chat once a username has been selected.
The username that a client selects should be unique to the chat room.
The client should be able to send and listen for messages concurrently.
The client should handle the server going offline abruptly in a graceful way.
The server should handle the client disconnecting abruptly in a graceful way.
The client should be able to send a disconnect request to the server and the server should then handle this gracefully.
When a client connects or disconnects from the chat room, all other clients that are connected should be sent a notification about this action of the client.
All input/output should be handled accordingly through the correct use of Exception Handling.
Before connecting to a server a client must first be asked what the address is of the server they wish to connect to.
When a client sends the server specific requests, these interactions should not be broadcasted to other clients in the chat room and should therefore only be visible by the client sending the request and the server.
TIPS:
Handling multiple client connections to the server can be done through the use of a Handler Class that extends the Thread base class.
The use of threads in the Client Class will allow you to correctly handle incoming messages and outgoing messages concurrently.
You can make use of the BufferedReader Class for incoming streams.
You can make use of the PrintWriter Class for outgoing streams.
Store each clients name in a HashSet to make it easy to check for duplicates when a client is selecting a user name. This will also help when the server responds to a clients request for the total count of connected clients.
Store each clients outgoing stream in a HashSet to make it easier to broadcast messages to all clients as soon as a new message is received by the server.
If you compile your solutions into .jar files then you will be able to test running multiple client connections easier as you can have a different console window showing the output for each client and the server.
The full solution should be in two separate Java projects as there will be two Main Methods, one for the server and one for the client.
You should not implement any GUI, please dont use your own packages.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.