Client Side:

  1. Client types the string “send” to the chatroom, triggers “handle_send_file_request()”.
  2. Client types the filepath of the file they want to send.
    1. Exit from this process if typed “exit”, or if the filepath is not valid.
  3. Client transmits the file to the server by doing the following steps:
    1. Create metadata (filename, filesize, hashedFileContent) of the file.
    2. Check if the filesize and the extension of the file are valid; exit from this process if either is invalid.
    3. Send an empty message with type prefix of “2” to server to inform the server that the client wants to send a file.
    4. Send the metadata of the file with type prefix of “2“ to server.
    5. Sleep for 1 sec.
    6. Send the content of the file (divided into each of size “chunk_size”, but with no type prefix) to the server.
  4. Client finishes its side of the upload process.

Server Side:

  1. Server receives an empty message with type prefix of “2”, knowing that the client wants to send a file, thus triggering “handle_upload_request()”.
  2. Server receives the metadata of the file from the client, then extracts out (filename, filesize, hashedFileContent) from the metadata.
  3. Server checks if the filesize and the extension of the file are valid; if either is invalid, the server <simply prints the “stopped receiving file” and returns>.
  4. Server receives the content of the file.
  5. If the received file is not None, server will add it to the room the sending client is in.
  6. Server finishes its side of the upload process.