Skip to content

metandrini/SyncOrSwim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sync or Swim

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%


INSTRUCTIONS

Make sure that your device and the device you are going to sync to are connected to the Internet.

[CLIENT]

  1. Run the client side of Sync or Swim program.
  2. 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).
  3. Paste the IP address of the destination device to the IP Address box.
  4. Enter a port number you would like to connect to in the Port Number box.
  5. Submit.

[SERVER]

  1. Run the server side of Sync or Swim program.
  2. Specify the destination folder the client would synchronize to (e.g.: /Users/lepton/Desktop/test2).
  3. Wait until the client initiates connection.

client.py

MainThread describes the client mechanism in creating requests and processing server responses.

run

Updates the client index.

send

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.

receive

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.

updateIndex

Updates file indices within the client directory in the form of a dictionary, excluding hidden directories and files.

syncFromServer

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.

syncToServer

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:

  1. 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.
  2. 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.
  3. 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.

getNametype

Returns whether a predetermined path based on input is a directory or a file.

wait

Receives connection from server on a non-conditional loop without processing any possible transmissions until the server sends an ‘OK’ signal.

getIndex

Updates client index, sends a request for server index, and then returns both client and server indices.

sendIndex

Sends client index as a dump package to the server.

displayThreads

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.

run

Iterates over the job queue and applies the changes to the client directory one by one.


server.py

ClientThread The ClientThread class describes the server mechanism in handling requests from the client.

run

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.

send

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.

receive

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.

getNametype

Returns whether a predetermined path based on input is a directory or a file.

sendTime

Retrieves the date and time from the system and sends it as a package to the client.

sendIndex

Updates the server index and sends the updated index as a dump package to the client.

wait

Receives connection from client on a non-conditional loop without processing any possible transmissions until the client sends an ‘OK’ signal.

updateIndex

Updates file indices within the server directory in the form of a dictionary, excluding hidden directories and files.

syncFromClient

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.

syncToClient

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:

  1. 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.
  2. 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.
  3. 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.

getID

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.

run

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.

run

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.

displayThreads

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.

About

Synchronizes directories and files between clients.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TeX 63.6%
  • Python 36.4%