Question
We are making a bidirectional sync application for pc and mobile phone.. and we are having issues on comparing the files, we cannot base on the time of the pc and mobile phone because most likely they are different. We also considered using crc, but again we encountered time related problem. If both files are modified then both their crc equivalent will be different, we can't determine which is the latest file. help! thanks in advance!
We are making a bidirectional sync application for pc and mobile phone.. and we are having issues on comparing the files, we cannot base on the time of the pc and mobile phone because most likely they are different. We also considered using crc, but again we encountered time related problem. If both files are modified then both their crc equivalent will be different, we can't determine which is the latest file. help! thanks in advance!
Answer
I'm assuming your trying to sync the entire file. That is, you want the latest version of the file on both systems when you're done. You MUST have accurate timestamps or you simply can't sync. You can read the time on both platforms to determine what the difference is between the two. Apply this difference to one of the time stamps so you can compare the dates/times on the two files. This isn't entirely trustworthy, but it's the best you can do. Your application could request that the user set the times to be as close as possible to each other. This procedure assumes you have stored the time that you last synchronized the PC and the phone: 1. If the file on the PDA was changed after the last sync time and the PC file is older than the last sync time, then the PDA file is newer and should be copied to the PC. 2. If the file on the PDA is missing and the file on the PC is older than the last sync time, then it was deleted from the PDA and should be deleted from the PC. 3. If the file on the PDA is missing and the file on the PC is newer than the last sync time, then the PC file is either new or was modified after the PDA file was deleted, so the PC file should be copied to the PDA. 4. If both files are newer than the last sync time you have a conflict and need to ask the user which to keep. 5-7. Repeat steps 1-3 substituting PC for PDA and vice versa. 8. Store the sync time so you have it for next time. You can apply a similar algorithm to sync the records in a database. You just need to timestamp each record.
I'm assuming your trying to sync the entire file. That is, you want the latest version of the file on both systems when you're done. You MUST have accurate timestamps or you simply can't sync. You can read the time on both platforms to determine what the difference is between the two. Apply this difference to one of the time stamps so you can compare the dates/times on the two files. This isn't entirely trustworthy, but it's the best you can do. Your application could request that the user set the times to be as close as possible to each other. This procedure assumes you have stored the time that you last synchronized the PC and the phone: 1. If the file on the PDA was changed after the last sync time and the PC file is older than the last sync time, then the PDA file is newer and should be copied to the PC. 2. If the file on the PDA is missing and the file on the PC is older than the last sync time, then it was deleted from the PDA and should be deleted from the PC. 3. If the file on the PDA is missing and the file on the PC is newer than the last sync time, then the PC file is either new or was modified after the PDA file was deleted, so the PC file should be copied to the PDA. 4. If both files are newer than the last sync time you have a conflict and need to ask the user which to keep. 5-7. Repeat steps 1-3 substituting PC for PDA and vice versa. 8. Store the sync time so you have it for next time. You can apply a similar algorithm to sync the records in a database. You just need to timestamp each record.


Leave a reply