The Assignment 2

For this assignment, the server must allow multiple clients connect the server at the same time. You are required to implement a multithreaded server (using Pthread or Java thread) and a client that can monitor the server's message and the users input at the same time (e.g. using select() or threads).

Besides the original five commands ADD, DELETE, LIST, SHUDOWN, QUIT, you will need to implement four new commands, LOGIN, LOGOUT, WHO, LOOK, on the client side and the corresponding functions on the server side.

The details of the protocol depend on the command the client sends to the server.

LOGIN

Identify the user to the remote server. A client that wants to login should begin by sending the ASCII string "LOGIN" followed by a space, followed by a UserID, followed by a space, followed by a Password, and followed by the newline character (i.e., '\n').

Your server should be initialized with the UserIDs and Passwords of at least four users who will be allowed to execute the ADD, DELETE, and SHUTDOWN (the root user only) commands at the server. However, a user is allowed to execute the LIST, WHO, LOOK, and QUIT commands anonymously (without login).

When the server receives a LOGIN command from a client, it should check if the UserID and Password are correct and match each other. If they are not correct or don't match each other, the server should return the string "410 Wrong UserID or Password," otherwise it should return the 200 OK message.

A client-server interaction with the LOGIN command thus looks like:

c: LOGIN john john01
s: 200 OK

LOGOUT

Logout from the server. A user is not allowed to send ADD, DELETE, and SHUTDOWN commands after logout, but it can still send LIST, LOOK, WHO, and QUIT commands.

A client-server interaction with the LOGOUT command looks like:

c: LOGOUT
s: 200 OK

WHO

List all active users, including the UserID and the users IP addresses.

A client-server interaction with the WHO command thus looks like:

c: WHO
s: 200 OK
The list of the active users:
john 141.215.69.202
root 127.0.0.1

LOOK

Look up a name in the book. Display the complete name and phone number record. A client sends the ASCII string "LOOK" followed by a space, followed by a number (1 - look for the first name, 2 look for the last name, 3 look for the phone number), followed by a name or a phone number, and followed by the newline character (i.e., '\n').

When the server receives an LOOK command from a client, it will look up the name or the phone number in the address book. When there is a match, it returns the "200 OK" message and all the matched record (s). If there is no match, it returns the 404 Your search did not match any records.

A client-server interaction with the LOOK command thus looks like:

c: LOOK 2 Miller
s: 200 OK
Found 2 match
1001 David Miller 313-510-6001
1004 John Miller 315-123-1345

c: LOOK 3 313-231-1324
s: 404 Your search did not match any records

ADD and DELETE

The basic requirement is the same as the assignment 1 except that a user needs to login first to execute these commands. If a user has not logged in, the server will return a "401 You are not currently logged in, login first" message

LIST

Same as the assignment 1.

SHUTDOWN

The basic requirement is the same as the assignment 1 except that only the "root" user can execute this command. When your server receives a SHUTDOWN command from a client, it should check if the current user is the root. If it is not the root user, the server should return a "402 User not allowed to execute this command" message.

In addition, the SHUTDOWN will make all clients and the server terminate.

A client-server interaction with the SHUTDOWN command thus looks like:

c: SHUTDOWN
s: 200 OK

At the windows of all clients

s: 210 the server is about to shutdown

QUIT

If a user logged in from the current client, QUIT also logout the user.

Note, a user can execute WHO, LIST, and QUIT commands before logged in.

Academic Honesty!
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.