15 Replies Latest reply on Jun 10, 2011 2:46 PM by Michael Thornburgh

    p2p Multicast. PublishNotification/Unpublishnotification Problem


      Hello Adobe Forum!


      First of all excuse my bad english


      How can get pass this following problem...

      Iam developing a multicast p2p audio/video app. So everbody is able to publish and recieve...


      i wrote a function that creates a new videodisplay for me and adds to my HBox.

      This function is fired up when the "NetGroup.MulticastStream.PublishNotify" event is dispatched.


      This works great!


      My another function deletes the VideoObjects from my Hbox if   the "NetGroup.MulticastStream.UnPublishNotify" event is dispatched.

      This works great to, but if somebody new joins in the room. he gets 5 new "NetGroup.MulticastStream.PublishNotify" events... and my function creates these objects on the stage. After approx. 5-10 seconds. The FlashPlayer checks that there is only one Publisher and sends 4 UnpublishNotifiys...


      Now i dont know where to start. I must update the Netgroups Publisher list correctly? I thought the netgroup would do it self. And if the answer is yes, how would I do that?


      I thougt to write a Timeout function if somebody connects. But this solution is not very nice!


      Thank you all!

      Hope it was understable




      Forgot to mention!

      If I dont connect to the group for lets say... 1-2 minutes everything is works great. But this Problem would be critical if a lot people would use it.

        • 1. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
          bahulu Level 1

          To explain it more in detail and shorter!


          How can i chek if the incoming streams are really published streams? I think the netgroups holds the streams for a specified time... untill it is completely deleted from the Netgroup...

          • 2. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
            bahulu Level 1

            Ok no reply, it seems that my question was not understandable...


            My Problem ist that the netgroup i think does not close the streams properly... What happens to me is. When i connect to a group i recieve multicast.PublishNotfiys. after few seconds sometimes minutes a UnPublishNotify arrives me...


            These notifys are from Publisher who already leaved the group. but the stream they've published are still alive in the group!

            • 3. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem

              Hello Adobe!  I would love to see a response to this, as I am working on a similar application and need to have a little assistance?


              My application also uses multicast to publish to members of the group.  I'm listening for the NetGroup.Neighbor.Connect event, and I'm calling the following function:


              protected function onPeerConnect(event:NetStatusEvent):void{
                              var peerID:String = event.info.peerID;

                              // create user vo here
                              // user Value Object for incoming stream
                              userVO = new User();
                              userVO.peerID = peerID;


              protected function receiveStream(userVO:User):void{
                              // init netstream
                              var stream:NetStream = new NetStream(nc,groupspec.groupspecWithAuthorizations());
                              // init panel
                              // alter to use custom component instead
                              var panel:Panel = new Panel();
                              panel.id = "panel" + panel_seq;
                              panel.title = "Panel" + panel_seq;
                              panel.x = 50 * panel_seq + 200;
                              panel.y = 25 * panel_seq + 200;
                              var cpanelContent:Array = new Array();
                              // init video
                              var video:Video = new Video();
                              // init videoWrapper
                              var videoWrapper:UIComponent = new UIComponent();
                              videoWrapper.id = "wrapper" + panel_seq;
                              // add to display list
                              // drag and drop panel
                              panel_seq++;// used for unique panel id
                              userVO.panel = panel;// reference to the panel
                              userVO.stream = stream;
                              userVO.video = video;


              I am confused on this:


              var stream:NetStream = new NetStream(nc,groupspec.groupspecWithAuthorizations());


              What should I pass as the second parameter to establish an incoming NetStream with the publishing peer?  I've seen people put in the farID but I haven't figured out how to access it.  What is the difference between event.info.peerID and event.info.neighbor?  And since I'm multicasting to the group do I need to pass in the groupspec or the farID?  I would love some clarification on this.


              What is happening is this:


              When I join the group, and there are two members in the group already, I'll get three panels with videos.  However, duplicate video streams are being attached.  When I inspect the peerStreams array I'm seeing a length of 0, so does that mean that no one is subscribing to my published netstream?  If so, how do I specifically subscribe to each published stream in the group?  Sometimes if I step through in debug mode, I get three separate camera feeds in their prospective panels, but if I run it will have duplicates.  I thought at first that this was a referencing error because all of the NetGroup.Neighbor.Connect events where happening all at the same time and perhaps that is the reason for the duplicates?


              My only other thought is that maybe I'm multicasting one guys stream to the whole group, but I'm getting varying results so I want to know what is the correct way to grab, in sequence, a NetGroup members' published netstream and be sure that all other members are subscribing to my NetStream as well?


              Also, I am using Value Objects to keep track of who my group members are, is that data shared with the group or is it not accessible to all members?  or should I use another method of keeping track of my group members?


              Please help!  Thank you in advance!

              • 4. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                Michael Thornburgh Adobe Employee

                a group keeps track of old closed streams for a time to dampen them out of the group.  i see the NetGroup.MulticastStream.PublishNotify for these closed streams sometimes.  that might be a bug.


                sometimes a publisher might terminate abruptly and not have a chance to cleanly close its multicast stream.  in that case the stream could exist in the group for several minutes before it times out and is considered closed.  in those cases it is appropriate to get a PublishNotify for a not-quite-dead-yet stream.


                for new PublishNotify events, you could play the stream but not attach it to a display object immediately.  instead you could watch its bandwidth stats and wait for there to be data (video, audio, etc) before attaching it to a display object.  that could at least keep your display from getting cluttered.

                • 5. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                  jdbeeler Level 1

                  If I am using net groups and I am multicasting video for a video chatting

                  application, should I use the groupspec for both the incoming and outgoing

                  streams or do I need to use peerID, farID?  I believe that is for direct

                  connections only.  I'm attempting to create a mesh of around 8 video

                  chatting windows.  When I inspect the peerStreams array its length property

                  is 0, does that mean that it isn't being subscribed to?

                  • 6. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                    Michael Thornburgh Adobe Employee

                    you don't need to call NetGroup.addNeighbor() for a neighbor you've been notified about with NetGroup.Neighbor.Connect; that peer is already your neighbor in that group.


                    note that you won't be neighbors with every member of a group.  in fact, you don't want to be neighbors with every member of a group if that group is really big (like 1,000 or 1,000,000 members, in fact, even 100 is too many).  you will typically have O(log n) neighbors in a group of n members.  note that neighbor relationships aren't permanent; a peer may disconnect from you but still remain in the group.


                    there can be multiple publishers in a group.  every member of the group will get every multicast stream, whether it's displayed or not.  each stream must have a unique name in order to be distinctly selected at a subscriber.  for example: if two members of a group each publish a stream called "livestream", and a third member subscribes to "livestream" in that group, it will select one of the two published streams (but you have no control over which is selected), and it's not possible to select the other.


                    NetGroup.MulticastStream.PublishNotify events will tell you the distinct names of the streams published in a group.  you don't need to (nor will doing so help) watch for neighbor connects to decide what streams are in a group.


                    when using RTMFP Groups NetStreams (for multicast), you use a group specification ("groupspec") instead of a peer ID.  peer IDs are used for subscribing to 1:1 DIRECT_CONNECTIONS NetStreams.  P2P multicast is a completely different operating mode.


                    in the NetGroup.Neighbor.Connect/Disconnect info object, the "peerID" is the peer ID of the neighbor that connected/disconnected, and the "neighbor" is the group address (position in the group ring mod 2^256) for that peer.  peer IDs and group addresses are related but not identical.  see the ActionScript documentation for NetGroup.convertPeerIDToGroupAddress() for more information.

                    • 7. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                      Michael Thornburgh Adobe Employee

                      you use a group specification for publishing and subscribing to multicast streams:


                        var ns:NetStream = new NetStream(nc, groupspec);





                      the peerStreams array only lists 1:1 stream subscribers.  every member of a group receives (and relays) every stream in that group, whether you subscribe/display or not.

                      • 8. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                        jdbeeler Level 1

                        Awesome!  Its so much easier to have someone explain it to you


                        You're my hero.

                        • 9. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                          jdbeeler Level 1

                          So is there an easy and efficient way of seeing all the streams that are being published in a group?  Or do I just respond to each NetGroup.MulticastStream.PublishNotify and use the event.info.name property to play the stream one at a time?


                          Also, what is the best way to keep track of the users in the group?  I have been using an arraycollection of Value Objects but I wondered about how that information should be shared with group members. 

                          • 10. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                            Michael Thornburgh Adobe Employee

                            you use the NetGroup.MulticastStream.PublishNotify/UnPublishNotify events to track the streams in a group.


                            as i explained earlier, RTMFP Groups are typically not fully meshed (it is not the case that every member is a neighbor of every other member). the "distributed presence" problem is more complicated than you think, especially if you want it to scale.


                            if your group is small (less than about 15 members), then it will be naturally fully meshed (every member will be a neighbor with every other member).  above about 15, the group will probably not be fully meshed.


                            for groups that aren't too large, you could use NetGroup.post() to periodically send a notice to all other members of the group that "you are here", and each member could track those messages and time out old ones.  this solution doesn't scale to large numbers of members because the group will be continuously flooded by presence messages.


                            please see this thread where i covered exactly the same topic:




                            here is a link to some potentially relevant research on epidemic/gossip graph diffusion:



                            • 11. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                              jdbeeler Level 1

                              Thank you for the responses, and on a holiday no less.  I have another question (or two) for you, if you will.


                              1. If I get a NetGroup.Neighbor.Disconnect, does that not necessarily mean that a member has left the group?  Could it be they are still a group member (and still be publishing a stream)? 
                              2. Is there a limit to how many streams can be shared in a group? 
                              • 12. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                                Michael Thornburgh Adobe Employee

                                1. NetGroup.Neighbor.Disconnect does *not* mean that a member has left the group.  it only means that the member is no longer directly connected to you.


                                there are some circumstances in which when *particular* neighbors disconnect from you, there is a high (but not guaranteed) probability that the member has actually left the group.  for example, if a neighbor is numerically adjacent (NEXT_INCREASING or NEXT_DECREASING) AND you are the corresponding numerically adjacent neighbor (in the other direction) for that member, then if that member disconnects from you, it has most likely left the group.


                                2. the only constraints on the number of streams that can be in a group are memory, bandwidth, and cpu at each member.  each stream takes up memory in each member; each active stream consumes bandwidth in the mesh as it is distributed to every member, and processing the multicast streams takes computational cycles at each member.  but no explicit numerical limit has been built into the system.

                                • 13. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                                  jdbeeler Level 1

                                  I see.  So I guess there is no definitive way to detect when a member has left the group?


                                  If I wait for an UnpublishNotify to remove the video, is that a reliable way to do it?  Would there be a delay in-between when the user actually leaves the group and when the UnpublishNotify event is fired?


                                  Is their a method for listing the streams that are being published in a particular group?  As long as every stream is cleanly closed then wouldn't that be a pretty accurate account of who is in the group, as long as I am requiring a stream to be published by every member?

                                  • 14. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                                    jdbeeler Level 1

                                    One more question.  If I call the close() method on a NetGroup, does that close the group for everyone else as well?  If so, how do I disconnect from the group without closing it off to everyone else?



                                    • 15. Re: p2p Multicast. PublishNotification/Unpublishnotification Problem
                                      Michael Thornburgh Adobe Employee

                                      there is a significant amount of overhead for each multicast stream in a group.  i wouldn't use one stream/member just to use the presence of the stream to indicate presence of a user.


                                      the publishing user disconnecting won't necessarily result in an immediate UnpublishNotify event.  it could take a while for that to happen, and new joining members might erroneously see the streams for users who aren't even in the group when the new member joins.


                                      the live distributed scalable presence problem is harder than you think it is, and the "live not-present-any-more" part of that problem is even harder.  you will have the best results with a gossip-based epidemic diffusion algorithm.  my immediately previous message in this very thread talks about that and includes links to another thread and a relevant research paper.


                                      NetGroup.close() only closes that specific handle to your local attachment to the group.  the group itself is a cooperative distributed system comprising all of its members; it isn't an object on one computer to which all other members connect.  you can have multiple NetGroup instances for the same group; each instance can be closed independently with no effect on the others, nor any effect on any other members of the group.