DESCRIPTION:

In this assignment, you will write a complete program in C to develop a simple chat room server and client. Clients establish sessions with the server to communicate with other logged in clients. Clients can see who all are presently logged in and can send messages to select clients or broadcast messages to all clients. Messages are expected to be short one-line messages.

Clients can also block other clients from sending messages to them. Clients can also unblock blocked clients.

REQUIREMENTS:

  • A server named chat_server shall be started with a port number as argument
  • Clients can connect to this server using the server IP address, port number and EUID
    • First argument is the server IP address
    • Second argument is the server port number
    • Third argument is the user name
    • Eg: ./chat_client 129.120.151.94 8888 ndg0068
  • Up to 30 clients can simultaneously connect to the server
  • Clients can issue one of three commands:
    • SEND:*:< message >
    • SEND:< euid >:< message >
    • LIST
    • QUIT
    • BLOCK:< euid >
    • UNBLOCK:< euid >
    • HELP
  • Command names (SEND, LIST, BLOCK, UNBLOCK, QUIT, HELP) are case- insensitive.
  • SEND:*< message > shall broadcast the command to all connected clients
  • SEND:< euid >:< message > shall send the message only to the specified client
  • LIST shall list all logged in users
  • QUIT shall log the user off the chat service.
  • BLOCK:< euid > shall block the user EUID from sending messages to the client that issues the BLOCK command
  • UNBLOCK:< euid > shall unblock the user EUID - that is, EUID can now send messages to the client that issued the UNBLOCK command
  • NOTE 1: BLOCK:< euid > blocks < euid > from sending messages to you; it does not prevent you from sending messages to < euid >. If < euid > wants to block you, then < euid > must issue a BLOCK with your euid.
  • NOTE 2: SEND:* shall ignore blocked clients and shall notify all logged in users including those clients that have blocked the user that is issuing the SEND:* command.
  • HELP shall display a list of supported commands
  • If an invalid command is entered, then HELP results shall be displayed
  • The server code shall correctly handle the following error situations:
    • Invalid user name in SEND, BLOCK, UNBLOCK commands
    • Unrecognized commands
    • Duplicate user names (if multiple clients attempt to connect to server using the same user name)
  • The server shall also generate log messages in its console indicating logging in and logging out of users
  • Note that a client should be able to send and receive messages from other clients simultaneously. The client interface should not block waiting for any other client to respond.
  • Your code should be well documented in terms of comments. For example, good comments in general consist of a header (with your name, course section, date, and brief description), comments for each variable, and commented blocks of code.

SAMPLE OUTPUT (user input shown in Red font):

(in first terminal)
$ ./chat_server
Please provide a port number to use.

(in first terminal)
$ ./chat_server 8888
Listening on port 8888
Waiting for connections ...

(in second terminal)
$ ./chat_client 129.120.151.94 8888 ndg0068
Welcome to the 3600 Chat Room!

When this connection is accepted, the server terminal (first terminal)
will show:
New connection, socket fd is 5, ip is: 129.120.151.94, port:
45838
User ndg0068 has logged in

(in second terminal)
LIST
ndg0068

(in third terminal)
$ ./chat_client 129.120.151.94 8888 abc1234
Welcome to the 3600 Chat Room!

When this connection is accepted, the server terminal (first terminal)
will show:
New connection, socket fd is 6, ip is: 129.120.151.94, port:
45906
User abc1234 has logged in

(in second terminal)
HELP
Valid commands are:
BLOCK:
LIST
QUIT
SEND:(< euid >|*):
UNBLOCK:< euid >
HELP

(in second terminal)
LIST
ndg0068
abc1234

(in third terminal)
SEND:ndg0068:Hello how are you?

(in second terminal)
From:abc1234
Hello how are you?

(in second terminal)
SEND:abc1234:I am doing fine, and you?

(in third terminal)
From:ndg0068
I am doing fine, and you?

(in second terminal)
BLOCK:abc1234
Done. You will not receive messages from aba1234

(in third terminal)
SEND:ndg0068:Hi there again, do you get this?
Sorry. User ndg0068 has blocked you.

(in second terminal)
UNBLOCK:abc1234
Done. You will receive messages from aba1234

(in third terminal)
SEND:ndg0068:Hi there once again, do you get this?

(in second terminal)
From:aba1234
Hi there once again, do you get this?

(in second terminal)
SEND:*:Everyone, the server will shut down shortly.

(in second terminal)
From:ndg0068
Everyone, the server will shut down shortly.

(in third terminal)
From:ndg0068
Everyone, the server will shut down shortly.

(in second terminal)
QUIT
5

(in server terminal – that is, the first terminal)
Host disconnected, ip 129.120.151.94, port 45838
User ndg0068 has logged out

(in third terminal)
LIST
abc1234
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.