In this project, you will implement the chatting program for multiple user. Upon successful implementation of this project, all team members will get 3% of extra credit on top of the final grade. If the team implements GUI for this application, additional 2% will be added (total of 5%). The details of the project are described as follows.
Â
Part 1: Server
The server provides a linking service among the clients (users); the terms âuserâ and âclientâ are interchangeably used throughout this project. When the server gets started, it reads a file (âaccount.txtâ) located in the server computer, that contains usersâ ids and passwords. Each line in the file contains an account information; id and password separated by one blank space.
Â
account.txt Example id1 password1 id2 password2 id3 password3 id4 password4 âŚ..
Â
After reading âaccount.txtâ file, the server displays the contents of the file and waits for TCP connection request from the client by opening server socket. At this time, server runs a thread for TCP connection from clients. This means that, a new thread will be created and be waiting for the next new TCP connection when one connection is made ď multithreaded server. The server can take up to 100 concurrent connections.
Â
When the server receives a connection request from any client, it must check how many concurrent connections/users are open/online at this moment. If it is larger than 100, the server sends an error message (the exact string âBUSYâ) to the client and doesnât accept the new connection. If not, it accepts the new connection and proceeds to the following steps.
Â
When the server receives connection requests from the clients, it just follows the same rules of Log-in Phase for Project 3.
Â
Once the client1 is successfully connected to the server, the server sends the list of users who are currently on-line and ready to chat. And the server waits for the client1âs message with the user id (e.g. client2âs user id). When the server receives the user id (with which the client1 wants to chat), it sends client2 the following message;
âCONNECTIONREQUESTEDâ followed by 2 port numbers, port number2 and port number1 (unique/unused port number randomly chosen by the server between 8000 and
9999), separated by â*â (âCONNECTIONREQUESTED*port number2*port number1â).
These 2 port numbers are unique and randomly chosen by the server between 8000 and 9999.
Then, the server waits for the ACK message from the client2. Once the server receives an
ACK message (âREADYâ) from the client2, it sends client1 the ip address of the client2
followed by port number1 and port number2; message format will be âclient2âs ip address*port number1*port number2â. After sending these 2 messages, the server waits for other messages from both clients.
Â
If the server receives a message âDONEâ, then it means that P2P chatting has been done and 2 involved clients are ready for another connection for chatting. When the server receives a message âDISCONNECTâ, then the socket connection is closed for that user. When the client leaves the server, the server must update the list of the users who are currently on-line and broadcast it to all clients who are still connected to the server.
Â
Part 2: Client1
The client1 will connect to the server using TCP connection. When the client1 gets started, it asks serverâs ip address and port number. Then the user will enter the information to connect to the server. When the client receives an error message (the exact string âBUSYâ) from the client and the connection will be terminated.
Â
The client1 follows the same rules of Log-in Phase for Project 3.
Â
Once the client1 logs in to the server, it will receive the list of users who are currently on-line and ready to chat. Then the client1 sends a user (client2âs user id) id in the received list with whom it wants to chat and waits for the response from the server. For this, the client1 program must check if the user enters the valid user id which is in the received list. If it is not, then the client1 program displays an error message and lets the user try again.
Â
Once the client1 receives the client2âs ip address, port number1 and port number2 from the server in the form of âclient2âs ip address*port number1*port number2â, then the client1 creates threads (one for server and the other one for client; bidirectional communication between users) to make the connection to the received ip address. port number1 is used client1âs server socket and port number2 is used for client1âs client socket. Once the client1 opens server socket using port number1 and waits for the connection from client2. Then, it uses a client socket to initiate the connection to client2âs server socket. client1 will receive a connection from client2 through server socket and bidirectional communication channel is established between client1 and client2.
Â
Each team will decide how to terminate the chatting.
Â
When client1 wants to leave the chatting system, it must send a message âDISCONNECTâ to the server. Then client1 will be removed from the list of available users in the server which will also update âaccount.txtâ.
Â
Part 3: Client2
Letâs assume that client2 is already online and is waiting for serverâs message. Once client2 receives a message (âCONNECTIONREQUESTED*port number2*port number1â) from the server, it opens a server socket using port number2 and waits for the connection from client1. In the meantime, client2 creates client socket and tries to connect to client1âs server socket using port number1. Now, bidirectional communication channel is established between client1 and client2.
Â
Each team will decide how to terminate the chatting.


