Create a command-line-based library management system using C++. The system should allow users to manage a library's collection of books. Users should be able to add, remove, and search for books, as well as perform other library-related functions.
make && make run [Port]
nc [server IP]:[Port]
Notic: The default server IP is localhost
, if you want to set the server IP to public, modify the macro PUBLIC
in server.hpp
The user need to register to be a member when the user connect to library-management-system.
Usage: register
Usage: login
When the user want to borrow a e-book/p-book.
You can use command books
to see all book id.
e
means the book type is e-book, p
means the book type is p-book.
Usage: add [book name/book id] [e/p]
When the user want to borrow a e-book/p-book.
Usage: rm [book name/book id] [e/p]
When the user want to read a e-book.
You can input "" to keep reading after command read
.
Usage: read [book name/book id] [e/p]
When the user want to check the state of specified book.
Usage: search [book name]
When the user want to see all book in the library-management-system.
Usage: books
When the user just want to check how many books in the personal bookshelf.
Usage: mybooks
On the server side, I establish a socket server. When an external connection is made, I create a new process using fork()
to handle that external connection. The stdin
, stdout
, and stderr
of that process can be redirected to the corresponding socket file descriptor.
To handle data that needs to be shared among multiple processes, such as library books and account/password management, I create shared memory. This allows different processes to access and modify the shared data. To deal with synchronization issues when accessing the shared data,I use semaphores
.
On the client side, I have written a UI class specifically designed to handle client requests and generate responses based on those requests.