Client Side:
- Client types the string “send” to the chatroom, triggers “handle_send_file_request()”.
- Client types the filepath of the file they want to send.
- Exit from this process if typed “exit”, or if the filepath is not valid.
- Client transmits the file to the server by doing the following steps:
- Create metadata (filename, filesize, hashedFileContent) of the file.
- Check if the filesize and the extension of the file are valid; exit from this process if either is invalid.
- Send an empty message with type prefix of “2” to server to inform the server that the client wants to send a file.
- Send the metadata of the file with type prefix of “2“ to server.
- Sleep for 1 sec.
- Send the content of the file (divided into each of size “chunk_size”, but with no type prefix) to the server.
- Client finishes its side of the upload process.
Server Side:
- Server receives an empty message with type prefix of “2”, knowing that the client wants to send a file, thus triggering “handle_upload_request()”.
- Server receives the metadata of the file from the client, then extracts out (filename, filesize, hashedFileContent) from the metadata.
- 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>.
- Server receives the content of the file.
- If the received file is not None, server will add it to the room the sending client is in.
- Server finishes its side of the upload process.