Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You need to write a server and client to allow chat between multiple users. Submit the server file, client file, and protocol file. Check that
You need to write a server and client to allow chat between multiple users.
Submit the server file, client file, and protocol file. Check that the server works
with multiple clients communicating simultaneously. Go over the example run
and make sure your programs runs the same.
Commands supported by the client
# NAME will set name. The server will reply with an error if the name
already exists
# GETNAMES will get all client names
# MSG will send to the client NAME
# EXIT will close the client and connection
Explanation
The NAME command allows you to determine a name for our customer. For
example, NAME A will set the name A for the client, so that messages
intended for A are now forwarded to it by the server. The server will answer it
with HELLO with the specified name. For example, HELLO A If the name A is
already occupied by another client, the server will reply that the name is taken.
A GETNAMES command will cause the server to send the client a list of all
client names that are connected to the server dont forget to remove
disconnected clients
An MSG command will send a message to the customer based on their name.
For example, MSG A HELLO will send HELLO to CLIENT A The server will first
add the senders name; for example, if B sent the message to A then A will
receive B SENT HELLO.
An EXIT order will cause the customer to be disconnected closing the socket.
Example run
The following screens show the following:
Client connects
The client sets the name A
Another Client connects
The client sets the name B
Client A checked which clients exist and received A B
Client B disconnected
Client A checked which customers exist and received A
Another Client connects
The client set the name B
Client A checked which clients exist and received A B
Client A sent a HELLO message to B
Client B received the message along with a message from the server
that the message was sent from A
Client B sent a HELLO message to A
Client B disconnects.
Client A disconnects.
General guidelines
Like the basic server exercise, you need to use a protocol file, which will
include a length field. The server and the client will use the length field in
communicating and not just recv
If the server receives an unknown command, it will return an appropriate
message to the client that sent the message.
If the server is prompted to forward a message to a client that does not
exist, it will return an appropriate message to the client that sent the
message.
Server writing guidance
Using the server code in the textbook, the main difference is that you need
to write a function that handles messages coming from the client. It is
recommended to have a data structure that will link a socket to a client
name; a Python dictionary can be useful.
Client writing guidance
As you may recall, the recv and input functions are blocking, meaning that
the customer will wait for information before moving on This will prevent
the program from running properly because the client may not be able to
receive user input until they receive a notification, and vice versa it will
not be possible to receive messages until the user has finished entering
input.
The solution consists of two parts.
Instead of the recv function, the client will use the select function. You
can set the timeout in seconds.
Instead of the input function, we import the msvcrt module an
important part of our skill is selfstudy of topics, explanations and
examples can be found on the Internet, so I am not attaching an
explanation Create code that receives a character at a time from the
user using the kbhit and getch functions, prints to the screen and after
receiving a line feed character Enter sends the message to the server.
Tip: When printing to the screen, use the flushTrue parameter so that
each character prints immediately to the screen.
Verification expected result score if not achieved
Basic functions
Connection of clients at the same time The server receives the clients Grade
Both clients execute NAME and then GETNAMES, their names appear in the list of clients they receive. The names of all customers are one word only, in English, case sensitive without special characters. Their names appear on the list of clients they receive Minus
A client sends a message to another client, only one word without any space. The other client receives the word, including the correct name of the client who sent it Minus
Client disconnects with EXIT. The server goes on running properly and does not crash or hang. Minus
A client sends a message that is not one of the defined messages. The server does not crash Minus
Application standardization
A client sends a oneword message to another client. The other client receives the message. Minus
A client sends a message to himself.
The message is received, or the client receives a message that it is not possible to send a message to yourself think abou
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started