Reference no: EM132182323
Project - Chatroom
Project Goal
Create a Chat application consisting of a chat client and a chat server. The client and server must be written in Python and must use sockets.
Introduction
The chat application allows multiple chat clients to connect to a chat server. Connected clients can:
- list the members already logged in,
- log in with a username,
- exchange messages with other logged in users,
- log out.
The server has to accept and maintain connections to all the clients and relay chat messages between them.
Chat Client Overview
The chat client application has to do the following tasks:
1. Connect to a chat server. The client obtains the server IP address and the port it is listening on. Then, the client immediately attempts to connect to the server socket using TCP.
2. Accept commands from the user. The client must be able to handle the following commands. Parameters are enclosed in <>:
- login <username>
- list
- sendto <username> <message>
- logout
- exit
Each line must begin with a command. The parameters (if any) are separated by a space. The commands and parameters are described in more detail below. In order to implement these commands correctly, the client will have to send and receive the following messages to/from the server:
a. Send messages to the server. The client must be able to send the following messages to the server.
- login message
- list message
- sendto message
- logout message
b. Accept incoming messages from the server. The client must be able to properly react to the following messages.
- LIST message
- RESPONSE message
- SENDTO message
Commands from client to server
We now present the commands that a client must handle. Note: whenever a client prints an error message, it should not perform any other action.
login: sends a login message to register with the server using the provided username.
Parameter(s): a string to be used as the username.
Rules:
The string may not contain any white space. Screen names are treated as case sensitive.
Any extra parameters after the username must cause the client to print an error. The error must also be printed if the username is more than 20 characters in length or if the username is not present. The following is the error:
Bad username
Examples:
The following is an example of a valid command:
login John
The following is an example of an invalid command:
login John Doe
list: sends a list message requesting the list of users already logged in.
Parameter(s): none
Rules:
Any extra parameters must cause the client to print the following error:
Invalid command
Examples:
The following is an example of a valid command:
list
The following is an example of an invalid command:
list bob
sendto: sends a sendto message to the server to communicate with another client.
Parameters: The user name of the destination client and the text to send.
Rules:
If either or both of the parameters are missing or if the username contains more than 20 characters, the following error message should be printed to the console:
Bad username
If there are more than 65535 characters of text, the following error message should be printed to the console:
Bad message
Examples:
The following is an example of a valid command:
sendto John Hello, how are you?
The following is an example of an invalid command:
sendto JohnHello
logout: sends a logout message to the server.
Parameters: none.
Rules:
Any extra parameters must cause the client to print the error:
Invalid command
The client should not close the connection with the server when executing this command. After executing this command, the client should still be able to execute the list and login commands.
Examples:
The following is an example of a valid command:
logout
The following is an example of an invalid command:
logout Joe
exit: closes the client socket and exits the program.
Parameters: Takes no parameters
Rules:
Any extra parameters must cause the client to print the error:
Invalid command
Examples:
The following is an example of a valid command:
exit
The following is an example of an invalid command
exit client
Protocol Overview: For each message that the client sends to the server the server will send a message back. For a successful list message the server will return a LIST message back. For all other messages or an unsuccessful list Message, the server will respond with a RESPONSE Message. The client never sends messages back in response to messages received from the server.
Messages Sent from Server to Client
The following is the structure for messages the client receives from the server.
LIST message: sent in response to successful list messages received from the client.
RESPONSE message: sent in response to all messages received from the client, except where list messages are appropriate.
If the server finds that a list message from the client has a problem (i.e. the server cannot provide the list of logged in users), it will send a response message, NOT a list message.
If result is ok, the client must print the following message:
Success
If result is failure, the client must print the following message:
Failure
If the result is malformed packet, there is something wrong with your code.
SENDTO message: sent whenever another client wishes to communicate with us.
Client should be able to receive this message whenever it is logged in.
Whenever this message is received, the client application has to print the message in the form "<username>: <text message>" to the console. For example if Bob sends "Hi how are you?" to John, then John's client should print out: Bob: Hi How are you?
Attachment:- Project Chatroom.zip