4 Replies Latest reply on Nov 19, 2010 12:42 AM by oohazard7

    p2p chat without group


      Hello everybody,


      I am playing with cirrus and would like to set up a p2p chat without netgroup. I have made it work for two peers but when I increase the number of peer I got some problem.


      The design:


      I am using one sendStream per peers (Each of them initialize the sendStream (sendStream.publish("media")) and send a message at a regular interval on this stream). sendStream.send("hello");


      every 10 seconds, the peers register themselves on a amfphp service which keep track of their id (random string), their cirrus peerID and a timestamp.

      at this point they also ask the service for a list of other connected peers (timestamp not older than 11 seconds)


      for each new peers connected (based on the service) every other peers create a recvStream that connect to the sendStream of each other peers. In case the recvStream stop (which happen for some reason ?), I restart it recvStream.play("media").



      The problem:


      When the thirs peers connect, not all peers receive messages;


      I also get a event.info.code == "NetStream.Play.PublishNotify" which I do not why (does not happen when only two peers are connected.



      The solution?


      I wonder whether it is because each sendStream can only handle one recvStream ?

        • 1. Re: p2p chat without group
          nimigeanu Level 2

          If I understand correctly you are trying to not use the NetGroup and instead direct-stream-connect each peer with all others. The approach looks unfeasible for a number of reasons, including poor scalability, waste of sockets, waste of bandwidth...


          ...plus the most important, 2 arbitrary peers are not guaranteed to successfully connect directly; yet in a group topology messages between otherwise unconnectable peers can be relayed by others, transparently or programatically. The chances of having everyone virtually connected to all others increase with the size of the group.


          Why are you trying to go without it?

          • 2. Re: p2p chat without group
            oohazard7 Level 1

            The main reason is that NetGroup does not handle friends group


            If I set a netgroup to send to my friends on facebook, I will successfully send them a message but in case they want to send a emssage back, they will send to everybody in the group which are not necessarely their friend (not all my friend are friends between each other). With netGroup I have  to create a group for each node and these groups should not be writable by the node's friends.


            imagien  I have ten friends currently connected. it means I have to read from ten groups and I have my own group for me to write to them as a group. Furthermore if I want private message I have to send them through a specific channel.


            It seems that in this case, a direct connection seems as good as netgroup, if not simpler.


            Also since I want to udnerstand how things work, I would like to know whether a sending netstream can have more than one receiver.


            I tried again with more simpler code and it seems that in case of flash peer to peer , netStream can only have one simulatenous suscriber. is it correct?

            Does it means that NetStream.peerStreams is always of length 1 ?


            the documentation does not talk about this and woudl like to know for sure.

            If that is thes case I ll have to have a connection handler channel and maintain peer connection channel for each friends. In which case NetGroup might be easier, but still requires maintaing several netgroup and setting writing access to the node sendign message.




            Note: the friend groups taht I want to setup is not intented to be used for chat (even if it could) but for data in a multiplayer game.


            Thank you for your help,





            • 3. Re: p2p chat without group
              nimigeanu Level 2

              Do not really know if a direct p2p stream should support multiple subscribers, but if it did that would still multiply the publisher's outbound bandwidth with the number of subscribers. To me this is bad.
              This is unlike the group where it publishes to only a handful of peers which further relay the packets to others.


              There's nothing wrong with connecting everybody to one big happy group, have arbitrary peers publish specific streams, then have only the few interested/permitted peers play some of them. If the group is reasonably large this would save the headache of unconnectable peers which IMHO is a big issue in your fully wired scenario.
              If you are concerned about leech peers playing a stream without authorization you may encrypt the info and distribute the keys via the centralized system.


              For genuinely private messages, since you have centralized control over the peerID's, you can addNeighbor() and then sendToNeighbor(); if addNeighbor() fails it would have also failed as a direct connection; you then need to implement some routing/forwarding to get your message across. If concerned about eavesdropping forwarders you should again encrypt the data.


              Hope this helps, good luck.

              1 person found this helpful
              • 4. Re: p2p chat without group
                oohazard7 Level 1

                Thanks zasdzasdzasd for the quick replies.


                This was helpful,

                also note that there is an disadvantage to send to a group where only few members care of the data since all actually receive it : http://forums.adobe.com/thread/752581?tstart=0

                So in my case I will have to create as many group as there is people online (1 group per flashplayer) and every flashplayer woudl have to connect to as many group as they have friend currently online (which should not hit the limit of bottsrapped group of 16 very often and if it does, capping to 16 would not be a big issue for the application I want to make). this also mean that the advantage of group routing is limited by the number of friend (members of the flashplayer group) online.



                now if someone can tell me whether p2p netStream can handle several suscribers or not, if so how to do it? and why in my case it fails?, I would be happy (I have a desire to know even if I end up not using that feature at all)


                the documentation seems to say that is possible since there is no special doc regarding p2p netstream.peersStream...


                Thanks all,