$25
Continuing the first part, you are asking to implement boards and posts in the Bulletin Board System (BBS). The server should be multiprocessing / multithreading, and the following function will be connected by TCP. Your posts should maintain in the shared memory, that is, all operations related to posts should be done in shared memory, and other operations have no limitation.
Requirement
The service accepts the following commands and at least 10 clients:
When client enter command incompletely, that is, missing parameters, the server should show command format for client.
If command is in the right format, the first failure message will have the higher priority, for example of the “create-board” command, the user didn’t login, then the result should be “Please login first”.
Command format
Description
Result
create-board <name>
Create a board which named <name>.
<name> must be unique.
If Board's name is already used, show failed message, otherwise it is success.
Must be logged in when creating board’s name.
There is no limit to do the operation by shared memory or database.
Success
Create board successfully.
Fail (1)
Please login first.
Fail (2)
Board already exists.
create-post <board-name> --title <title>
--content <content>
(command is in the same line)
Create a post which title is <title> and content is <content>.
Use --title and --content to separate titles and content.
<title> can have space but only in one line.
<content> can have space, and key in <br> to indicate a new line.
Do the operation by shared memory.
Assign a unique serial number to each post. The serial number will start from 1 and increase by creating post.
Success
Create post successfully.
Fail (1)
Please login first.
Fail (2)
Board does not exist.
Scenario
bash$ client 127.0.0.1 7890 ********************************
** Welcome to the BBS server. ** ********************************
% create-board NP_HW Please login first.
% register Bob bob@qwer.asdf 123456 Register successfully.
% register Sam sam@qwer.com 654321 Register successfully.
% login Bob 123456 Welcome, Bob.
% create-board NP_HW
Create board successfully.
% create-board NP_HW
Board already exists.
% create-board OS_HW
Create board successfully. % create-board FF
Create board successfully.
% list-board
Index Name Moderator
1 NP_HW Bob
2 OS_HW Bob
3 FF_HW Bob
% create-post NCTU --title About NP HW_2 --content Help!<br>I have some problem!
Board does not exist.
% create-post NP_HW --title About NP HW_2 --content Help!<br>I have some problem!
Create post successfully.
% create-post NP_HW --title HW_3 --content Ask!<br>Is NP HW_3 Released?
Create post successfully.
% list-post NP
Board does not exist.
% list-post NP_HW
% read 100
Post does not exist.
% read 1
--
Help!
I have some problem!
--
% update-post 100 --title NP HW_2 Post does not exist.
% update-post 1 --title NP HW_2 Update successfully.
% read 1
--
Help!
I have some problem!
--
% logout
Bye, Bob.
% login Sam 654321 Welcome, Sam.
% update-post 1 --content Ha! ha! ha!
Not the post owner. % delete-post 1 Not the post owner.
% comment 100 Ha! ha! ha!
Post does not exist.
% comment 1 Ha! ha! ha!
Comment successfully.
% read 1
Author: Bob
Title: NP HW_2
Date: 10/26
--
Help!
I have some problem!
--
Sam: Ha! ha! ha!
% create-board Hello
Create board successfully.
% list-board
Index Name Moderator
1 NP_HW Bob
2 OS_HW Bob
3 FF_HW Bob 4 Hello Sam
% logout
Bye, Sam.
% login Bob 123456 Welcome, Bob.
% delete-post 1
Delete successfully. % read 1
Post does not exist.
% logout
Bye, Bob.
% exit
Reference
1. C/C++ Socket
2. SQLite C/C++ Interface
3. Linux socket SELECT
4. Linux semaphore
5. Linux fork