0 Replies Latest reply on May 20, 2011 1:42 PM by rafael.baggio

    Cirrus p2p direct connect problem

    rafael.baggio

      Hello guys,

       

      I`m trying to make a direct connection to call remote methods in my application, everything looks fine except for the remote method call that doesn`t happen.

       

      Here`s my code:

       

       

      package client.services

      {

      import flash.display.MovieClip;

      import flash.events.NetStatusEvent;

      import flash.net.NetConnection;

      import flash.net.NetStream;

       

      import client.display.DisplayManager;

      import client.globals.User;

       

      public class P2P extends MovieClip

      {

           private const CirrusAddress:String = "my_cirrus_adress";

           private const DeveloperKey:String = "my_key";

       

           private var netConnection:NetConnection;

           private var sendStream:NetStream;

           private var recvStream:NetStream;

       

           private var _callback:Function;

           private var _client:Object;

       

       

           public function P2P()

           {

                super();

           }

       

       

           public function connect(callback:Function = null):void

           {

                _callback = callback;

                netConnection = new NetConnection();

                netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);

                netConnection.connect(CirrusAddress, DeveloperKey);

           }

       

       

           private function netConnectionHandler(e:NetStatusEvent):void

           {   

                var code:String = e.info.code;

       

             

       

                if(code == "NetConnection.Connect.Success")

                {

       

                     User.connKey = netConnection.nearID;

       

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

                     sendStream.addEventListener(NetStatusEvent.NET_STATUS, onSendStreamHandler);

                     sendStream.publish("mystream");

       

                     _callback();

                }

           }

       

       

           public function createUserConnection(friendID:String):void

           {

                recvStream = new NetStream(netConnection, friendID);

                recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);

                recvStream.play("mystream");

                _client = this;

           }

       

       

           private function netStreamHandler(e:NetStatusEvent):void

           {

                if(e.info.code == "NetStream.Play.Start")

                {

                     sendStream.send("myFunction");

                }

           }

       

       

           public function myFunction():void

           {

                //This is the method to be remotely called.

           }

       

       

           private function onSendStreamHandler(e:NetStatusEvent):void

           {

                if(e.info.code == "NetStream.Play.Start")

           {

      }

       

       

      Sorry for my english and thanks in adivice!