0 Replies Latest reply on Jun 24, 2011 8:40 PM by BryBam

    How can I automatically connect to multiple connecting streams? to have 2 way communications foreach

    BryBam Level 1

      I need to setup a send stream that will only allow each farID to connect 1 time, and automatically connect to the connector so I ca have 2 way communication.

       

      I learned if in my onpeerconnect function i do this...:

       

      var c:Object = new Object;

      c.onPeerConnect = function(subscriber:NetStream):Boolean

      {  

         if(ready==ready)

          {

         if(receiveStream==null)

          {

          setupReceiveStream(subscriber.farID);

          return true;

          }

          }

          else

          {

          return false;

           }

      }

       

       

      it seems to work fine, and they will start a 2 way connection BUT i want to potentially allow multiple connections, and setup multiple receive streams so im trying to com up with a solution to check if its already streaming to the peer. I wish I could just do this:

       

      var c:Object = new Object;

      c.onPeerConnect = function(subscriber:NetStream):Boolean

      {  

          setupReceiveStream(subscriber.farID);

          return true;

       

      }

       

       

      But, for some reason it just keeps returning true over and over and over it doesnt just do it once on the connect, i get something like this:

      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start
      NetStream.Play.Reset
      NetStream.Play.Start

       

       

       

      So, heres what im trying to do:

       

      protected function setupSendStream():void

      {

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

      sendStream.addEventListener(NetStatusEvent.NET_STATUS, sendStreamHandler);

       

       

      var c:Object = new Object;

      c.onPeerConnect = function(subscriber:NetStream):Boolean

      {

       

       

      var test:Boolean=true;

       

      var THEStream:NetStream = null;

      for each (var stream:NetStream in sendStream.peerStreams)

      {

      if (stream["farID"] == subscriber.farID)

      {

      well=false;

      trace("found it!");

      }

      }

       

      if(test)

      {

      setupReceiveStream(subscriber.farID);

      trace("returned true");

      return true;

      }

      else

      {

      trace("returned false");

      return false;

      }

       

       

      }

       

      sendStream.client=c;

       

      sendStream.publish("MyChannel");

      trace("SETUP SEND STREAM");

      cirrusStatus=connectedReady;

       

      }

       

       

       

       

       

      But it seems like after it returns true and runs the setup, so i can have 2 way communication, it runs the onpeerconnect function 1 more time after it returns true, and its a return false and then it makes the play fail and it ruins the connection.

       

      Any ideas on how I can listen for connects to my sendStream, then have it get the farID and then connect to that farID?

       

      keep in mind im trying to potentially support multiple connections to my sendstream which i think will be easy, but whats more confusing is having multiple receivestream connections