7 Replies Latest reply on Jan 26, 2012 1:33 PM by Michael Thornburgh

    Maximising the number of successful connections

    DevChaz5 Level 1

      I'm finding that about 75% of the time two peers can connect to each other successfully. But sometimes they can't, even if they're on the same LAN. This only seems to happen when the peers are in a browser or using the standalone flash player. If one of them is inside the CS5.5 environment, this problem doesn't occur and the connection always seems to be successful. Could this maybe mean there are some security settings that are relaxed in the authoring environment, which would otherwise cause the connection to fail? Or is there some other reason for this? How can I ensure the most connections will be successful?

       

      A seperate question is if anyone knows if it's correct that FMS Interactive 4.5 can be used in Cirrus' place? I know that up until now it's only been available in FMS Enterprise, but according to this video:

       

      http://tv.adobe.com/watch/max-2011-develop/advanced-p2p-with-rtmfp-tips-and-tricks/

       

      At 5:30 seconds he says FMS Interactive 4.5 can do it as well now.

       

      Thanks!

        • 1. Re: Maximising the number of successful connections
          Michael Thornburgh Adobe Employee

          there are no differences in RTMFP that should account for the success rate discrepancy you're seeing.  if an RTMFP connection works between two computers once, it should work every time, not 75% of the time. i would have to know more about your application to make a guess as to why you're seeing what you're seeing.

           

          according to

           

            http://www.adobe.com/products/flashmediaserver/helpmechoose.html

           

          Flash Media Interactive Server 4.5 allows 500 concurrent RTMFP connections for P2P introduction.

          • 2. Re: Maximising the number of successful connections
            DevChaz5 Level 1

            Hi Michael, thanks for the reply. I'm going back over this issue and I've not been able to solve it.

             

            My laptop and my desktop are on the same local network and I've had plenty of successful RTMFP connections between them, a few this morning infact, using exactly the same piece of code as I'm using right now, but now they won't connect.

             

            I initially followed this video to set the whole thing up: http://flashrealtime.com/tuts/p2p-in-flash.html

             

            The chain of events that would normally lead to a successful set up stops after the second machine calls initRecvStream to try and receive the first machines sendStream. Normally in successful connections this might take a few seconds before the NetStream.Connect.Success event is triggered. In my case when they don't connect the event isnt triggered at all, which is the same as what happens when two machines that can never establish a connection try and connect to each other.

             

            It might be worth noting I'm currently using the Cirrus service.

             

            I'm trying to nail down under exactly what circumstances the connection fails and when it succeeds but I'm not having much luck, as right now it won't go through at all. I'm trying to think what it could be, are there any flash security settings that might cause this? Local policy files? Are certain versions of the flash player incompatible with each other for RTMFP? (Saw a thread about that but you said it's not an issue with Cirrus). Will having several instances of the flash player open cause problems, or several different simulateous connections?

             

            Is there anything I can tell you that might help to work this out?

             

            Any help is genuinely appreciated.

            • 3. Re: Maximising the number of successful connections
              Michael Thornburgh Adobe Employee

              all versions of Flash Player since 10.0 are compatible with each other for RTMFP 1:1 P2P.  the incompatibility issue i referred to was between Flash Player (or AIR) and servers, such as Flash Media Server, and particularly to do with using RTMFP Groups and the "server control channel", where the handshake for the server control channel was changed, requiring an updated server. the Cirrus servers were already updated.

               

              there are no security settings or other settings that would account for intermittent P2P success. as i said earlier: it should work 100% or 0%, but not in between.

               

              does the VideoPhoneLabs sample app work reliably? if so, that suggests an error of some sort in your code.

              • 4. Re: Maximising the number of successful connections
                DevChaz5 Level 1

                Thanks for the fast response!

                 

                The VideoPhoneLabs sample does work reliably, so it does suggest I'm doing something wrong.

                 

                What I'm putting together is a multiplayer game, where one player starts a game and their peerID is stored in a database, similarly to the video chat sample. Other players then join by receiving the hosts netstream, then sending their own.

                 

                I've just discovered that if the room 'host' is running from within my development environment (Flash CS5.5) then my laptop can connect successfully. If the host is running from firefox, or the standalone flash player, then the laptop cannot connect.

                 

                Does this shed any light?

                • 5. Re: Maximising the number of successful connections
                  DevChaz5 Level 1

                  I've taken the code exactly as it is from that 'p2p in flash' video and created an identical application in Flash CS5.5. I compile the .swf and send it to my laptop, so I've got the swf on both my laptop and my desktop. I'm running the .swf in the standalone flash player, and from locations I've added as trusted location settings, otherwise flash throws a security error.

                   

                  In these circumstances, the connection is unsuccessful. When initRecvStream is called from the second machine after initSendStream is called on the first, they don't connect and the onPeerConnect event is never triggered.

                   

                  But if on my desktop I run the .swf within Flash CS5.5 by compiling it, and on the laptop it's the same as before, the connection is successful and everything works fine. According to what you've said this shouldn't happen?

                   

                  This is the code I'm using:

                   

                   

                  import flash.net.NetConnection;

                  import flash.events.NetStatusEvent;

                  import flash.net.NetStream;

                   

                  const SERVER_ADDRESS:String = "rtmfp://p2p.rtmfp.net/";

                  const DEVELOPER_KEY:String = //removed my key

                   

                  var nc:NetConnection;

                  var myPeerID:String;

                  var farPeerID:String;

                  //streams

                  var sendStream:NetStream;

                  var recvStream:NetStream;

                   

                  buttonSendData.addEventListener(MouseEvent.CLICK, sendSomeData);

                  buttonConnect.addEventListener(MouseEvent.CLICK, initConnection);

                   

                  buttonInitSendStream.addEventListener(MouseEvent.CLICK, initSendStream);

                  buttonInitRecvStream.addEventListener(MouseEvent.CLICK, initRecvStream);

                   

                   

                  function initConnection(me:MouseEvent = null):void{

                     

                      if (txtFingerprint.text){

                          farPeerID = txtFingerprint.text;

                      }

                     

                      nc = new NetConnection();

                      nc.addEventListener(NetStatusEvent.NET_STATUS, ncStatus);

                      nc.connect(SERVER_ADDRESS+DEVELOPER_KEY);

                     

                   

                  }

                   

                  function ncStatus(event:NetStatusEvent):void{

                      trace(event.info.code);

                     

                      myPeerID = nc.nearID;

                     

                      txtFingerprint.text = myPeerID;

                  }

                   

                  function initSendStream(me:MouseEvent = null):void{

                      trace("initsendstream");

                     

                      sendStream = new NetStream(nc, NetStream.DIRECT_CONNECTIONS);

                      sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

                      sendStream.publish("media");

                     

                      var sendStreamClient:Object = new Object();

                      sendStreamClient.onPeerConnect = function(callerns:NetStream):Boolean{

                         

                         

                          farPeerID = callerns.farID;

                         

                          trace("onPeerConnect "+farPeerID);

                         

                          return true;

                      }

                     

                      sendStream.client = sendStreamClient;

                  }

                   

                  function initRecvStream(me:MouseEvent = null):void{

                     

                      recvStream = new NetStream(nc, farPeerID);

                      recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

                      recvStream.play("media");

                     

                      recvStream.client = this;

                  }

                   

                  function receiveSomeData(str:String):void{

                      txtReceiveData.text = str;

                  }

                   

                  function sendSomeData(me:MouseEvent = null):void{

                      sendStream.send("receiveSomeData", txtSendData.text);

                  }

                   

                  function netStatusHandler(event:NetStatusEvent):void{

                      trace(event.info.code);

                  }

                   

                  Am I doing something stupid? I really appreciate you looking into this!

                  • 6. Re: Maximising the number of successful connections
                    DevChaz5 Level 1

                    After some more hair pulling I've found something else strange.

                     

                    I've changed the program so that you can enter the respective far peer ID into each instance, in order to initialise the receive stream. Previously you entered one far ID, connected to it, and when this connection was established the host received the clients ID through onPeerConnect and did the reverse.

                     

                    Now I've found that if one tries to receive the others stream, it isn't successful. But if they BOTH try to receive each others streams at the same time, both succeed. This is using the standalone player.

                     

                    So, we've got computers A and B.

                     

                    A and B connect to the cirrus service, and they both call initSendStream. I then manually give each machine the others far peer ID.

                     

                    If only A calls initRecvStream, it fails.

                     

                    If only B calls initRecvStream, it also fails.

                     

                    But if A calls initRecvStream and straight after B calls initRecvStream, both are successful.

                     

                    Could I maybe be getting these strange results because both machines are behind the same router?

                    • 7. Re: Maximising the number of successful connections
                      Michael Thornburgh Adobe Employee

                      if both computers are behind the same NAT, AND both have some kind of local firewall that only allows UDP in from an address if it first sends UDP out to that address, AND your NAT doesn't do hairpinning, then a direct connection won't work unless both ends try to connect to each other at the same time.