Last updated
Last updated
This assignment has automated tests! Make sure to read the and to download the framework before starting.
In the chat client assignment, you used a server hosted by the teaching team. This server connects multiple clients and forwards messages between them. In this assignment, you implement your chat server using the same protocol.
Unlike the client, the server is likely to have multiple open connections at the same time—one for each client that is connected to it. Because it is impossible to predict when a client will send a request or message, your server needs to keep checking all connections for incoming data. Both polling and multi-threading are allowed as solutions to this problem.
Important: tests will expect a server to start at address 127.0.0.1 and port 5378 (even though you can develop your server using another address and port). The address and port will be, as well, supplied via test script when starting your server script using the --address
and --port
. Thus tests will start your server script as python3 server.py --address "127.0.0.1" --port 5378
. After the server has started and is ready to accept incoming connection the tests will expect a server to output Server is on
.
Protocol Requirements:
PR1: Your server must support the full protocol specified in the . This is the same protocol as the one used in the Chat Client assignment.
PR2: Receiving a HELLO-FROM
message from a user that is not authenticated should trigger an attempt to log the user in with their provided username.
PR3: If a user logs in with a valid username that is not in use, the server must send a HELLO
message in response.
PR4: If a user logs in with an invalid username, the server must send a BAD-RQST-BODY
message in response and close the connection.
PR5: If a user logs in with a username that is in use, the server must send an IN-USE
message as a reply and close the connection.
PR6: If a user that has already logged in attempts to send a HELLO-FROM
log-in request, the server must respond with a BAD-RQST-HDR
message.
PR7: If a user who has not already logged in attempts to send anything other than a HELLO-FROM
log-in request, the server must respond with a BAD-RQST-HDR
message and close the connection.
PR8: If a logged-in user sends a LIST
message, the server must reply with a LIST-OK
message.
PR9: The body of the LIST-OK
message must be a comma-separated list, containing only exactly the usernames of all currently logged-in users.
PR10: If a logged-in user sends a SEND
message to the server with a valid recipient, the server must send a DELIVERY
message to the target recipient.
PR11: If a logged-in user sends a SEND
message to the server with a valid recipient, and the server forwards it successfully, the server must send a SEND-OK
message to the original sender.
PR12: The SEND-OK
message must not be sent before the corresponding DELIVERY
a message has been successfully sent.
PR13: If a logged-in user sends a SEND
message to the server, where the target recipient is not logged in, the server must respond with a BAD-DEST-USER
message.
PR14: If a SEND
message cannot be forwarded to the specified recipient for any reason, no SEND-OK
the message must be sent.
PR15: If a user sends a HELLO-FROM
message when the server is full, the server must respond with a BUSY
message.
PR16: If any error stemming from an invalid message header occurs during operation, other than specified above, the server must send a BAD-RQST-HDR
message in response.
PR17: If any error stemming from an invalid message body occurs during an operation, other than specified above, the server must send a BAD-RQST-BODY
message in response
Username Requirements
UR1: Usernames must not contain spaces.
UR2: Usernames must not contain commas.
Technical Requirements:
TR1: The server must support 16 concurrent users
TR2: The server must use Threading or Polling to support concurrent connections.
TR3: The server must detect when users disconnect and remove them from the logged-in user list.
TR4: The server must not use sendall() function
TR5: The server must print Server is on
on startup when ready to start accepting client conenctions.