Last updated
Last updated
This assignment has automated tests! Make sure to read the and to download the framework before starting.
The remote chat client can be reached at
IP: 212.132.114.68
PORT: 5378
Due to privacy reasons the LIST command on public server will only output echobot's name. You can still send messages to any logged in client but you cannot get their name via LIST command; thus you need to know their name before sending a message. Local server distributed via the jar file implements a fully functioning LIST command listing names of all logged in users
You cannot use os.exit() function to terminate your program
In this assignment, you implement a text-based chat client. You use Python, sockets, and the Transmission Control Protocol (TCP) for this. Once you are comfortable using the socket interface, using sockets in other programming languages should be straightforward. After completing this assignment, you can exchange messages with fellow students using your client.
The chat client and chat server are built on top of TCP and use their application-layer protocol. This means the client and server can request the other to perform actions by sending predefined types of messages. For example, your client can ask the server to forward a message to another user’s client by sending the string SEND <username> insert your message here\n
to the server, where <username>
is the user to whom you want to send your message. If your message is correct, the server will send two messages: one to the destination user, forwarding your message, and one back to you that says SEND-OK\n
, to notify you that your message was forwarded successfully. Keep in mind that these messages can be of any length. Therefore, you need to make sure that your client can handle arbitrary message lengths.
Similar to Web browsers and other modern applications, your chat client does not expose the protocol it uses to the user. Instead, it provides a user-friendly text-based interface that makes it easy for users to chat with others without knowing the protocol specifications. The specifications of this interface, and the requirements of this assignment, are listed below. For automated tests, we require your chat client to precisely follow a pre-defined text interface.
Important: tests will expect your client to connect to a server at address 127.0.0.1 and port 5378 (even though you can develop your client using the external server). The address and the port will be, as well, supplied via test script when starting your client script using the arguments --address
and --port
. Thus tests will start your client script as python3 client.py --address "127.0.0.1" --port 5378
.
We include requirement IDs to be used with the tests.
Authentication Requirements:
Note: If the log-in handshake fails, the server will close the connection with your client. Reasons for a failed handshake include providing an invalid or taken username, sending the wrong header, etc.
RA1: The client must ask the user for a username and attempt to log them in.
RA2: The client must ask the user for a new username if the provided one is already in use, with an informative message.
RA3: The client must inform the user if the server is full and exit gracefully.
RA4: The client must inform the user if their username was rejected for any other reason and ask for a new username. Examples include forbidden symbols (!@#$%^&*)
RA5: The client must inform the user if their username was rejected for any other reason and ask for a new username. Examples include commands (@username, !who)
RA6: The client should not have to be restarted after a failed log-in attempt.
RA7: The client should be able to send a message to echobot and receive the full message
RA8: The client should be able to stop the program with !quit
at any point (including when asking for the name)
Special Command Requirements:
RC1: Typing the command !quit at any point must exit the client. No additional steps should be required to exit (e.g., Ctrl+C).
RC2: Typing the command !who must print a list of users.
Technical Requirements:
RT1: The client must use the TCP transport layer protocol for all network communication.
RT2: The client must not use the sendall()
function in Python.
RT3: The client must not print incomplete messages.
RT4: The client must support the sending and receiving of messages of any nonzero length.
RT5: The client must print messages as soon as they are fully received.
RT6: Awaiting user keyboard input should not prevent newly incoming messages from being displayed.
RT7: Receiving any protocol header from the server at any point in the client's lifetime must be handled appropriately. See Appendix A for all headers.
Interface Requirements:
RI1: The client must not print any of the protocol headers (see Appendix A in the Lab Guide). This applies to ALL the user workflows
RI2: On a startup, the application must print: Welcome to Chat Client. Enter your login:
RI3: If the login was successful, the application must print: Successfully logged in as <username>!
RI4: If login failed because the username is already in use, the application must print: Cannot log in as <username>. That username is already in use.
RI5: If login failed because of a malformed username, the application must print: Cannot log in as <username>. That username contains disallowed characters.
RI6: If login failed because the server is full, the application must print: Cannot log in. The server is full!
RI7: The messages must be sent by typing: @<username> <message>
RI8: If the message was sent successfully, the client must print: The message was sent succesfully
RI9: If the message was sent to a user that does not exist, the client must print: The destination user does not exist
RI10: When the user receives a message, the chat client must print From <username>: <message>
RI11: The client must receive the list of users received after !who
a command as:
There are <user count> online users:
- <username_1>
- <username_2>
...
- <username_n>
RI12: The message displayed when the header is malformed must be: Error: Unknown issue in previous message header.
R13: The message displayed when the body is malformed must be: Error: Unknown issue in previous message body.