1 Reply Latest reply on Jul 23, 2012 2:53 AM by atilaman

    Rtmfp + NetConnection + AIR 2.6 for iOS + wifi.

    walken_75

      Hello everybody,

       

      I'm currently trying to make an application (a game pad) for iOS (iphone only) with AIR 2.6.

      This application have to communicate with a game done in AIR running on a computer thanks to the wifi.

       

      I have read all articles about p2p and rtmfp that I was avaible to find this week end on the internet but nothing help me.

      And I don't wana use Cirrus.

       

      To test the concept I have do simple application.

      Here is the code of the AIR application that must run on the computer :

       

      import flash.net.NetConnection;

      import flash.events.NetStatusEvent;

      import flash.net.NetGroup;

      import flash.net.GroupSpecifier;

       

       

      initServer();

       

       

      var connection:NetConnection;

      var deviceGroup:NetGroup;

      var gs:GroupSpecifier;

       

       

      var datas:Object = {};

       

       

      var numberOfNeighbor:int = 0;

       

       

      function initServer():void{

                //Initialisation de la connexion

                connection = new NetConnection();

                //Lors de la récéption du NetStatus

                connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                //Lancement de la connexion

                connection.connect("rtmfp:");

      }

       

       

      function onNetStatus(e:NetStatusEvent):void{

                //trace(e.info.code);

       

                //Si la connexion réussi

                if(e.info.code == "NetConnection.Connect.Success"){

                          trace("Succefully connected to the network.");

                          trace("Trying to set the group.");

                          setGroup();

                }

       

                //Si la connexion au groupe réussi

                if(e.info.code == "NetGroup.Connect.Success"){

                          trace("Succefully connected to the group.");

                }

       

                //Si la connexion au groupe ne réussi pas

                if(e.info.code == "NetGroup.Connect.Failed"){

                          trace("Connection to the group failed.");

                }

       

                //Si la connection au groupe est regetée

                if(e.info.code == "NetGroup.Connect.Rejected"){

                          trace("Connection to the group rejected.");

                }

       

                //Si un voisin ce connecte

                if(e.info.code == "NetGroup.Neighbor.Connect"){

                          trace("Neighbor connected.");

                          numberOfNeighbor++;

                          trace("There is actually " + numberOfNeighbor + " neighbors connected and me, the server.");

       

                }

       

                //Si un voisin ce déconnecte

                if(e.info.code == "NetGroup.Neighbor.Disconnect"){

                          trace("Neighbor disconnected.");

                          numberOfNeighbor--;

                          trace("There is actually " + numberOfNeighbor + " neighbors connected and me, the server.");

                }

       

                //Si des informations sont reçues

                if(e.info.code == "NetGroup.SendTo.Notify"){

                          datas = e.info.message;

       

                          trace(datas.data1);

                          trace("bla");

                }

      }

       

       

      function setGroup():void{

                //Initialisation et paramètrage d'un groupe d'autorisations

                gs = new GroupSpecifier("connectedDevicesGS");

                gs.routingEnabled = true;

                gs.ipMulticastMemberUpdatesEnabled = true;

                //Ip a rejoindre

                gs.addIPMulticastAddress("227.110.8.8:35353");

                gs.multicastEnabled = true;

       

                //Initialisation du group

                deviceGroup = new NetGroup(connection, gs.groupspecWithAuthorizations());

                deviceGroup.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

      }

       

       

       

      That is the code for the application application that must run on the iPhone :

       

      import flash.net.NetConnection;

      import flash.events.NetStatusEvent;

      import flash.net.NetGroup;

      import flash.net.GroupSpecifier;

      import flash.events.MouseEvent;

       

       

      initClient();

       

       

      var connection:NetConnection;

      var deviceGroup:NetGroup;

      var gs:GroupSpecifier;

       

       

      var datas:Object = {};

       

       

      this.addEventListener(MouseEvent.CLICK, sendDatas);

       

       

      function initClient():void{

                //Initialisation de la connexion

                connection = new NetConnection();

                //Lors de la récéption du NetStatus

                connection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                //Lancement de la connexion

                connection.connect("rtmfp:");

      }

       

       

      function onNetStatus(e:NetStatusEvent):void{

                //trace(e.info.code);

       

                if(e.info.code == "NetConnection.Connect.Success"){

                          trace("Succefully connected to the network.");

                          consoleTxt.text += "Succefully connected to the network. \n";

                          trace("Trying to set the group.");

                          consoleTxt.text += "Trying to set the group. \n";

                          setGroup();

                }

       

                if(e.info.code == "NetGroup.Connect.Success"){

                          trace("Succefully connected to the group.");

                          consoleTxt.text += "Succefully connected to the group. \n";

                }

       

                if(e.info.code == "NetGroup.Connect.Failed"){

                          trace("Connection to the group failed.");

                          consoleTxt.text += "Connection to the group failed. \n";

                }

       

                if(e.info.code == "NetGroup.Connect.Rejected"){

                          trace("Connection to the group rejected.");

                          consoleTxt.text += "Connection to the group rejected. \n";

                }

       

                if(e.info.code == "NetGroup.Neighbor.Connect"){

                          trace("Neighbor connected.");

                          consoleTxt.text += "Neighbor connected. \n";

                }

       

                if(e.info.code == "NetGroup.Neighbor.Disconnect"){

                          trace("Neighbor disconnected.");

                          consoleTxt.text += "Neighbor disconnected. \n";

                }

      }

       

       

      function setGroup():void{

                //Initialisation et paramètrage d'un groupe d'autorisations

                gs = new GroupSpecifier("connectedDevicesGS");

                gs.routingEnabled = true;

                gs.ipMulticastMemberUpdatesEnabled = true;

                //Ip a rejoindre

                gs.addIPMulticastAddress("227.110.8.8:35353");

                gs.multicastEnabled = true;

       

                //Initialisation du group

                deviceGroup = new NetGroup(connection, gs.groupspecWithAuthorizations());

                deviceGroup.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

      }

       

       

      function sendDatas(e:MouseEvent):void{

                datas.data1 = "data number 1";

                deviceGroup.sendToAllNeighbors(datas);

      }

       

      When I open some instance of the .swf of the iPhone client, all neighbors are detected.

      If I compile the AIR application that must be the game, the one who have to run on the computer, all neighbors are detected too.

       

      But if I compile the AIR app for iOS and launch it from my iPhone this neighbor (the iPhone) is not detected and he don't detect instancies of the games / other iPhone app .swf opened on the computer.

       

      Of course the iPhone is connected to the same wifi than the computer.

       

      The strange part is that I have already do that but with an Android App and it was perfectly working.

       

      I wasn't avaible to find a descriptor file for iOs like there is one for Android where you have to say, you know, "ALLOW NETWORK ACCESS" and stuff like that. Is there one ?

       

      Any ideas ?

       

      Thanks for help. ^_^

       

      Cheers,

       

      Walken.

       

      EDIT : I just test the application on an other network and it's working.

      On my home wifi this is not working but on the office wifi it's working...

      That's realy strange. My home wifi musn't be correcly configured...

      One more time, any ideas about this ? ^_^