The only program that synchronizes your directories swimmingly!
Written by: Irsyad Nabil 1406546134 Meta Andrini Utari 1406546153
Team 4 Participation: Meta - 30% Irsyad - 70% Isaac - 0% Amel - 0%
Make sure that your device and the device you are going to sync to are connected to the Internet.
[CLIENT]
- Run the client side of Sync or Swim program.
- Choose the folder the contents you would like to synchronize to another folder, and paste the directory path to the Directory box (e.g.: /Users/lepton/Desktop/test).
- Paste the IP address of the destination device to the IP Address box.
- Enter a port number you would like to connect to in the Port Number box.
- Submit.
[SERVER]
- Run the server side of Sync or Swim program.
- Specify the destination folder the client would synchronize to (e.g.: /Users/lepton/Desktop/test2).
- Wait until the client initiates connection.
MainThread describes the client mechanism in creating requests and processing server responses.
Updates the client index.
Sends all packages in the queue to the server within a critical condition so that the packages would be sent in order. The packages are byte-encoded, and the string '?magic?' is a makeshift codeword indicating the end of transmission.
Receives incoming connection through socket. Received packages go through a 4096-byte buffer and the connection stops when a '?magic?' string is received. This function returns received packages in byte format.
Updates file indices within the client directory in the form of a dictionary, excluding hidden directories and files.
Synchronizes the contents from the server directory to the client directory. First, it would send the client index to the server for comparison. If the job is to copy a file/directory, then it would store the corresponding file/directory from the server and append it with the job type to the job queue. Other job types are added to the job queue as is.
Synchronizes the contents from the client directory to the server directory. Since the client is "in charge" of handling the synchronizing, so to speak, this function is equipped to handle 3 primary cases:
- A file/directory exists in server but not in client. In this case, the file/directory in question will be removed from the server directory.
- A file/directory exists in client but not in server. In this case, the file/directory in question will be copied to the server directory.
- A file/directory exists in both client and server. In this case, the modification time of the file/directory in question will be compared. The older copy of the two will be updated with the most recently modified copy.
Returns whether a predetermined path based on input is a directory or a file.
Receives connection from server on a non-conditional loop without processing any possible transmissions until the server sends an ‘OK’ signal.
Updates client index, sends a request for server index, and then returns both client and server indices.
Sends client index as a dump package to the server.
Prints out the details of all spawned threads, including an information of whether a thread is alive. The list of threads is sorted by their keys.
WorkerThread describes the mechanism of writing the changes made after synchronization unto the local (client) disk.
Iterates over the job queue and applies the changes to the client directory one by one.
ClientThread The ClientThread class describes the server mechanism in handling requests from the client.
Processes every thread that is received one at a time by determining which action to take based on the request code of the thread. The parsing of the threads continue until the TCP socket connection is closed or when a keyboard interrupt occurs.
Sends all packages in the queue to the client through an available socket. The packages are byte-encoded, and the string '?magic?' is a makeshift codeword indicating the end of transmission.
Receives incoming connection through socket. Received packages go through a 4096-byte buffer and the connection stops when a '?magic?' string is received. This function returns received packages in byte form.
Returns whether a predetermined path based on input is a directory or a file.
Retrieves the date and time from the system and sends it as a package to the client.
Updates the server index and sends the updated index as a dump package to the client.
Receives connection from client on a non-conditional loop without processing any possible transmissions until the client sends an ‘OK’ signal.
Updates file indices within the server directory in the form of a dictionary, excluding hidden directories and files.
Synchronizes the contents from the client directory to the server directory. First, it would send the server index to the client for comparison. If the job is to copy a file/directory, then it would store the corresponding file/directory from the client and append it with the job type to the job queue. Other job types are added to the job queue as is.
Synchronizes the contents from the server directory to the client directory. Since the server is "in charge" of handling the synchronizing, so to speak, this function is equipped to handle 3 primary cases:
- A file/directory exists in client but not in server. In this case, the file/directory in question will be removed from the client directory.
- A file/directory exists in server but not in client. In this case, the file/directory in question will be copied to the client directory.
- A file/directory exists in both server and client. In this case, the modification time of the file/directory in question will be compared. The older copy of the two will be updated with the most recently modified copy.
Assigns an ID to a thread within a critical section.
WorkerThread describes the mechanism of writing the changes made after synchronization unto the remote (server) disk.
Iterates over the job queue and applies the changes to the server directory one by one.
ListenThread describes the server mechanism in listening to any incoming connections from the client.
Listens for connections; and when there exist incoming connections from the client, it can handle up to 10 connections. In handling these connections, the function has to wait for an available socket before creating a new thread for them.
Prints out the details of all spawned threads, including an information of whether a thread is alive. The list of threads is sorted by their keys.