The goal of this assignment is to learn to make a multi-threaded TCP server in Python.
You will also gain experience designing your own protocol to meet a set of requirements.
Overview
You are building a file storage server that allows clients to store and retrieve files from a directory on a server (similar to a simplified version of FTP).
The server is connection-oriented with clients needing to authenticate via a password.
The server needs to support multiple clients who may be storing and retrieving large files all at the same time.
Thus your server must be multi-threaded.
For simplicity, you can assume all files live in the same directory as the client and server program.
You can also assume clients will avoid accessing the same filename at the same time.
The exact protocol you implement is up to you, but your program should meet the requirements detailed below.
Your software should be robust to incorrect input from the user.
In particular, your client and server should not crash, even if:
The user enters an incorrect password.
The user tries to get a file that does not exist.
The user tries to put a file that does not exist.
The user types an incorrect command.
Large files are sent or received.
Several clients are sending/receiving files at the same time.
We suggest you use TCP and base the "command-and-control" part of your communication around sending lines of text terminated by \n.
Remember that TCP is just a stream of bytes!
You cannot rely on send() or recv() returning the same number of bytes as the other side of the connection.
You should first study our multi-threaded client/server that upper cases lines of text: TCPClientMulti.pyTCPServerMulti.py
Client requirements:
One required command-line parameter (password), and two optional parameters (server name and port). Default server name is localhost and default port is 12000.
On startup, sends password to server to be checked.
If password is incorrect, prints a message and then exits.
If password is correct, prints good login message and displays a list of available commands.
Lets the user type a command specifying whether to retrieve a file, send a file, or quit.
User can continue issuing commands until a quit command is issued.
If command doesn't match a supported command, prints an error message.
When retrieving a file, prompts for filename then attempts to retrieve the file from the server.
If server does not have matching file, client displays a file not found error.
If server has a matching file, client displays size of file, then receives entire file, writing into current directory.
When sending a file, prompts for filename.
If file does not exist in client's current directory, prints an error message.
If file exists, displays size of file and sends the entire file to the server.
Can send and receive large files, even binary ones such as images or zip files.
Server requirements:
One required command-line parameter (password), and one optional parameter (port). Default port is 12000.
Must support multiple clients simultaneously.
Checks a new client's password against its own password.
If it does not match, inform the client and then shutdown the client's connection.
If it does match, inform the client and then wait for further instructions from client.
If the client is retrieving a file, look for the requested filename in the current directory.
If the file does not exist, inform the client.
If the file does exist, send the entire file to the client.
If the client is sending a file, write the entire file to the current directory (overwriting any existing file).
If the client asks to quit, shutdown its connection.
Submission.
Submit your programs FileClient.py and FileServer.py via Moodle.
Be sure each submitted source file has the required header with your name, username, and a description of the program.
Programs should use descriptive variable names and appropriate levels of commenting (explain at a high-level the goal of different sections of code).