5 Replies Latest reply on Oct 7, 2010 1:44 AM by nimigeanu

    Object replication - multiple file sharing

    Ivan Najman

      Hi to all,


      When sharing file i create chunks of data from the shared file and then


      call addHaveObjects


      netGroup.addHaveObjects(0, packetLenght);


      where packetLength is number of chunks actual data is being divided.


      I added listeners for request and result




      netGroup.writeRequestedObject(event.info.requestID, object.chunks[event.info.index]);




      in this info.code i would iterate chunks and addWantObject(i,i) where i is current chunk, that way i would add all chunks to addWantObject





      This works fine when sharing file to the other peers, but only first time, when i do repeat the scenario once again for same or different file nothing happens.

      NetGroup.Replication.Request - never gets called


      Entire source code i followed to recreate file sharing functionality can be found at



        • 1. Re: Object replication - multiple file sharing
          nimigeanu Level 2

          Object indexes are unique to the group and they should always point to the same object data.


          When you do...


          netGroup.addHaveObjects(0, packetLenght);


          ...you are declaring "i have these pieces of informations willing to share" to the group
          Your second call with the same parameters would have no effect as you have already declared that and the group already "knows" you have those; since the peers who wanted them already have these fetched they're no longer needed and NetGroup.Replication.Request does not get called again


          For a different file you should assign different id's for "startIndex" and "endIndex" and make sure the ranges never overlap; given your piece of code it looks like you always start at 0; throughout the group never send different data under the same object index

          • 2. Re: Object replication - multiple file sharing
            Ivan Najman Level 1

            Ok thanks very much


            I figured out another solution, and that is :


            When publisher finishes with sending packages it will invoke removeHaveObject, thatway  after publishing another data subscriber will addWantObject with correct ids.


            Thanks again

            • 3. Re: Object replication - multiple file sharing
              nimigeanu Level 2

              Sorry but that's not how object replication is intended to work.


              Even if data originates at some single peer, your "publisher", the others should also contribute (addHaveObjects) once they received some pieces, to redistribute these within the mesh, otherwise you will be exhausting the publisher's bandwidth and missing a lot of what object replication has to offer.


              This way there's no telling for the "publisher" when everybody has all the data and can move on sending the next "file" under the same indexes. Also, the information should also be available for peers that join at a later time.


              If you want to send data "on demand" from a single peer and only to whoever is present at the time you can do this via group multicast [NetStream.send()]

              • 4. Re: Object replication - multiple file sharing
                Ivan Najman Level 1

                I see ... but problem is that i want to send file to everybody present at the moment, if i use netstream.send() that way i will be sending data using UDP and there is no way to be sure that all data is transfered correctly


                With object replication i can be sure that data will be sent to all peers


                What do you think about it ?

                • 5. Re: Object replication - multiple file sharing
                  nimigeanu Level 2

                  Hello again,


                  Setting NetStream.dataReliable to true should take care of data integrity despite the UDP.

                  Dont really know what would happen to peers that lack the bandwidth to receive all that's being sent into the netStream, i guess something would eventually get lost at high datarate.


                  If your "files" are small and/or unfrequent multicast may be the way to go. Otherwise it's back to object replication.


                  Let us know how it went.