Client Side:

  1. Client types the string “recv” to the chatroom, triggers “handle_recv_file_request()”.

  2. Client types the directory they want the file to be downloaded to their device. The directory is then be checked for existence.

    1. Exit from this process if the directory is None or does not exist.
  3. Client types the filename of the file they want to download to the directory they just specified. The filename is then be checked for validness.

    1. Exit from this process if the filename is not valid.
  4. Client send the json of (directory, name) with type prefix of “3” to the server.

  5. Client waits, until receiving the directory with type prefix of “2”, knowing that the server wants to send the requested file, thus triggering “recv_file_from_server()”.

  6. Client waits, until receiving either “file_exists” or “file_not_found”, with type prefix of “0”, from server.

    1. Exit from this process if received “file_not_found”.
  7. Client receives the metadata of the file from the server, then extracts out (filename, filesize, hashedFileContent) from the metadata.

  8. Client checks if the filesize and the extension of the file are valid; if either is invalid, the client <simply prints the “stopped receiving file” and returns>.

  9. Client receives the content of the file.

  10. Client finishes its side of the download process.

Server Side:

  1. Server receives the json of (directory, name) with type prefix of “3”, knowing that the client wants to receive a file, thus triggering “handle_download_request()”.

  2. Server extracts out (directory, name) from the json.

  3. Server sends the directory with type prefix of “2” to client to inform the client to receive an incoming response from server.

  4. Server checks the room the requesting client is currently in, that if the requested file is actually stored on server.