$25
Description
Continuing the second part, you are asked to write a multiservice program in client-side. In addition to connecting to the original(BBS) server, you need to add the function of creating chatroom service. Unlike BBS, the chatroom is a directly interactive environment. The client can create a chatroom TCP server that other clients can join, and the client who creates the chatroom needs to store the chat record and manage the connections.
BBS Requirements
The service can serve at least 10 clients. Your server and client program must be able to handle all commands in the previous part (output results must be the same as the previous part).There are some new commands you have to implement for BBS service. These commands are described as follows:
(You don’t need to consider that users login on a different client-side and all ports used will be different.)
Command format
Description
Result
create-chatroom <port>
Create a chatroom which is named <username> in the client-side.
Each user can only create one chatroom.
Server store <port> to let other clients join chatroom.
After getting a response from the server successfully storing access info(e.g. port , host), the client-side starts to create a chatroom Server.
Failed execution:
Fail (1): No user logged in.
Fail (2):User has already created the chatroom.
Note: You have to send this command and get associated
Success
start to create chatroom…
(action:create chatroom server. )
Fail (1)
Please login first.
Fail (2)
User has already created the chatroom.
message by TCP.
list-chatroom
List all Chatroom_ame, chatroom_status
(open or close)
Fail (1): No user logged in.
Note: You have to send this command and get associated message by UDP.
Success
Chatroom_name Status
<chatroom_name> <status_1>
<chatroom_name> <status_2>
Fail (1)
Please login first.
join-chatroom <chatroom_name>
Join other chatroom server.
To join the chatroom, you must login. The client get access info from BBS server to join chatroom server.
When the client newly joins or rejoins, the client will get the latest three chat records , and the system reminds everyone in the chatroom that someone has joined us.
Failed execution:
Fail (1): No user logged in.
Fail (2):The chatroom does not exist.
Note: You have to send this command and get associated message by TCP.
Success
Action: connection to chatroom server.
Fail (1)
Please login first.
Fail (2)
The chatroom does not exist or the chatroom is close.
attach
The instruction is for the chatroom owner.
Attach the chatroom but the system will not send out a reminder.
Failed execution:
Fail(1) : No user logged in. Fail(2) : User does not create a chatroom.
Fail(3): User’s chatroom is closed.
Note:This command is a client-side command and does not need to be sent to the BBS server.
Success
Welcome to the chatroom.
Fail(1)
Please login first.
Fail(2)
Please create-chatroom first.
Fail(3)
Please restart-chatroom first.
restart-chatroom
Restart the chatroom, when the chatroom is closed.
The status of chatroom changed to "open".
After getting a response from the server successfully changing status, the client-side starts to create a chatroom Server.
Failed execution:
Fail(1) : No user logged in.
Fail(2) : User did not create a chatroom.
Fail(3) : The status of the chatroom is still “open”.
Note: You have to send this
Success
start to create chatroom… action:create chatroom server.
Fail(1)
Please login first.
Fail(2)
Please create-chatroom first.
Fail(3)
Your chatroom is still running.
command and get associated message by TCP.
logout
If this user has created a chatroom,the system reminds the user to do” attach” and “leave-chatroom” first .
Failed execution:
Fail(1) : No user logged in.
Fail(2) : Chatroom server is running.
Note: You have to send this command and get associated message by TCP.
Succes
Bye, <username>.
Fail(1)
Please login first.
Fail(2)
Please do “attach” and “leave-chatroom” first.
exit
Close chatroom and connection to BBS.
Chatroom Requirements
The chatroom TCP server can serve at least 5 clients. ,you are asked to implement a directly interactive environment. Each chat record contains the sender, send time, and message. When the client newly joins or rejoins , the client will get the latest three chat records(does not contain system messages).There are some new commands you have to implement for chatroom service. These commands are described as follows:
leave-chatro om
If your role is chatroom owner.
Take the following action.
step1: Close chatroom server.
step2: The status of chatroom changed to "close". step3: Switch mode to the original server (BBS).
If your role is not chatroom owner. Take the following action.
step1:Switch mode to the original server (BBS).
Note: You have to send this command and get associated message by TCP.
Success
Welcome back to BBS.
detach
The instruction is for the chatroom owner. Detach the chatroom but do not close the chatroom.
Note:This command is a client command and does not need to be sent to the BBS server.
Success
Welcome back to BBS.
Scenario
Run your server first, and run your client program to connect to your server. If the line only shows
“% “, that means we type <Enter> in our client program. It is just for the height alignment of two columns here. You can ignore that. The sample outputs of the client program are listed as follows:
assume demo environment in localhost
Client 1
Client2
bash$ ./client 127.0.0.1 7890
**************************
*Welcome to the BBS server.*
**************************
% register Brad bb@cs.nctu.edu.tw 123 Register successfully. %
bash$ ./client 127.0.0.1 7890
**************************
*Welcome to the BBS server.*
**************************
% register Bob bob@cs.nctu.edu.tw 123 Register successfully.
%
% login Brad 123 Welcome, Brad. %
% login Bob 123 Welcome, Bob.
%
% create-chatroom 8080
start to create chatroom…
*************************
**Welcome to the chatroom**
*************************
% list-chatroom
chatroom-name status
Brad open
(everyone in chatroom get system messages except Bob)
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us. hello Bob.
% join-chatroom Brad
*************************
**Welcome to the chatroom**
*************************
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
*************************
**Welcome to the chatroom** *************************
Brad[4:07] : hello Bob. hello Brad.
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
bob[4:07] : hello Brad.
Nice to meet you.
*************************
**Welcome to the chatroom** *************************
Brad[4:07] : hello bob. hello Brad.
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
Bob[4:07] : hello Brad.
Nice to meet you.
*************************
**Welcome to the chatroom** *************************
Brad[4:07] : hello Bob.
hello Brad.
Brad[4:08] : Nice to meet you.
me too.
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
Bob[4:07] : hello Brad.
Nice to meet you.
Bob[4:08] : me too.
*************************
**Welcome to the chatroom** *************************
Brad[4:07] : hello Bob.
hello Brad.
Brad[4:08] : Nice to meet you.
me too.
leave-chatroom
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
Bob[4:07] : hello Brad.
Nice to meet you.
Bob[4:08] : me too.
sys [4:09] : Bob leave us.
leave-chatroom Welcome back to BBS.
% whoami
Bob
% join-chatroom Brad
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
Bob[4:07] : hello Brad.
Nice to meet you. Bob[4:08] : me too.
sys [4:09] : Bob leave us. sys[4:10] : Bob join us.
detach
*************************
**Welcome to the chatroom** *************************
Bob[4:07] : hello Brad.
Brad[4:08] : Nice to meet you. Bob[4:08] : me too.
*************************
**Welcome to the chatroom** ************************* sys [4:06] : Bob join us.
hello Bob.
Bob[4:07] : hello Brad.
Nice to meet you. Bob[4:08] : me too.
sys [4:09] : Bob leave us. sys[4:10] : Bob join us.
detach
Welcome back to BBS. %
*************************
**Welcome to the chatroom** *************************
Bob[4:07] : hello Brad.
Brad[4:08] : Nice to meet you.
Bob[4:08] : me too.
% create-chatroom 8080
User has already created the chatroom.
%
% restart-chatroom
Your chatroom is still running.
%
% logout
Please do “attach” and “leave-chatroom” first.
%
*************************
**Welcome to the chatroom** *************************
Bob[4:07] : hello brad.
Brad[4:08] : Nice to meet you. Bob[4:08] : me too.
hello everyone.
% attach
*************************
**Welcome to the chatroom** *************************
Bob[4:07] : hello brad.
Brad[4:08] : Nice to meet you. Bob[4:08] : me too.
hello everyone.
% attach
***************************
**Welcome to the chatroom** ***************************
Brad[4:08] : Nice to meet you.
Bob[4:08] : me too.
Bob[4:11] : hello everyone.
leave-chatroom
*************************
**Welcome to the chatroom** *************************
Bob[4:07] : hello brad.
Brad[4:08] : Nice to meet you. Bob[4:08] : me too. hello everyone.
% leave-chatroom Welcome back to BBS.
% list-chatroom
chatroom-name status
Brad close
% restart-chatroom
*************************
**Welcome to the chatroom** *************************
Bob[4:07] : hello brad.
Brad[4:08] : Nice to meet you.
Bob[4:08] : me too. hello everyone. sys[4:12] : the chatroom is close.
Welcome back to BBS.
%
% restart-chatroom
start to create chatroom…
*************************
**Welcome to the chatroom**
*************************
Brad[4:08] : Nice to meet you.
Bob[4:08] : me too.
Bob[4:11] : hello everyone.
% leave-chatroom
Welcome back to BBS.
% logout bye , Brad.
% restart-chatroom
Please create-chatroom first.
%
% restart-chatroom Please login first.
% exit bash$
Grade (100%)
● create-chatroom command – (10%)
● list-chatroom command – (10%)
● join-chatroom command – (10%)
● leave-chatroom command – (10%)
● restart-chatroom command – (10%)
● attach command – (10%)
● detach command – (10%)
● logout command - (10%)
● Chatroom messages match the format – (10%)
● Client gets the latest three chat records when joining the chatroom – (10%)
Submission
Please upload a zip file called “hw3_{$student_id}.zip” (e.g., hw3_0856020.zip) that includes your source code. It must include at least your server source code and client source code. Submission that doesn’t follow the rule will get 20% punishment on the grade.
You will get 0 points on this project for plagiarism. Please don’t copy-paste other students’ code!