I’m making a small peer-to-peer app that holds a common collection of objects. This isnt a question about the socket comms to transfer the objects as I have that sorted.
To start with I dont have to worry about conflicts as the clients can only add to the object collection. But I’m struggling to work out in my head how the clents negotiate which objects they need to transfer to each other.
I would guess this has been done many times before, and there must be some sort of sync algorithm out there somewhere…
Any ideas?
UPDATE:
I guess I’m asking if there is a way to sync without having to cycle through all the objects on each peer and check that they exist at the other end
If you use an
ObservableCollectionof serializable objects implementingINotifyPropertyChanged, you can queue the objects for transmission as they are altered. If you keep the objects that need synchronization in aHashSet, you can avoid double-entries in the queue at the expense of linear ordering. If you carefully overrideGetHashCode(), or even better create a method that returns a stronger hash, you can filter out items that changed equally on both ends.Edit: For the initial sync, build a packet that lists the generated hashes of all the current objects as a binary block. That way the exchange is quick.