• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

chat conection problems in different networks

New Here ,
Oct 15, 2013 Oct 15, 2013

Copy link to clipboard

Copied

i have this chat application and it only transmit and connect if both computers are in the same network and IP, but if they use different networks it doesn´t conect, please some body help

code

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                 xmlns:s="library://ns.adobe.com/flex/spark"

                                 xmlns:mx="library://ns.adobe.com/flex/mx"

                                 width="668" height="600" minWidth="0" minHeight="0"

                                 creationComplete="application1_creationCompleteHandler(event)">

          <s:layout>

                    <s:VerticalLayout   paddingBottom="5"

                                                                      paddingLeft="5"

                                                                      paddingRight="5"

                                                                      paddingTop="5" />

          </s:layout>

          <fx:Script>

                    <![CDATA[

                              import mx.events.FlexEvent;

                              import spark.components.mediaClasses.VolumeBar;

                              private var nc:NetConnection;

                              private var recebeStream:NetStream;

                              private var enviaStream:NetStream;

                              private var camera:Camera;

                              private var video:Video;

                              private var mic:Microphone;

                              private var fr:FileReference;

                              private var bytes:ByteArray;

                              protected function application1_creationCompleteHandler(event:FlexEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        nc = new NetConnection();

                                        nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

                                        nc.connect("rtmfp://p2p.rtmfp.net/adfd30ed9533e7ab2ee7643e-8ba6a1b88a71/");

                              }

                              private function onNetStatus(event:NetStatusEvent):void

                              {

                                                  txtOutput.text += event.info.code + "\n";

                                                            if (event.info.code=='NetConnection.Connect.Success')

                                                            {

                                                                      txtOutput.text += 'farID: ' + nc.farID + '\n';

                                                                      txtOutput.text += 'nearID: ' + nc.nearID + '\n';

                                                                      iniciarEnvio();

                                                            }

                              }

                              private function iniciarRecebecimento():void

                                        {

                                                  recebeStream = new NetStream(nc, txtFarID.text);

                                                  recebeStream.client = this;

                                                  recebeStream.addEventListener(NetStatusEvent.NET_STATUS, onRecebeDados);

                                                  recebeStream.play('chat');

                                                  recebeVideo();

                              }

                              private function recebeVideo():void

                              {

                                        video = new Video;

                                        video.width = 320;

                                        video.height = 240;

                                        video.attachNetStream(recebeStream);

                                        videoRemoto.addChild(video);

                                        recebeStream.receiveVideo(true);

                                        recebeStream.receiveAudio(true);

                              }

                              private function iniciarEnvio():void

                              {

                                        txtNearID.text= nc.nearID;

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

                                        enviaStream.client = this;

                                        enviaStream.addEventListener(NetStatusEvent.NET_STATUS, onEnvioDados);

                                        enviaStream.publish('chat');

                              }

                              private function capturaMic():void

                              {

                                        //var st:SoundTransform = new SoundTransform(0);

                                        mic = Microphone.getMicrophone();

                                        //mic.soundTransform = st;

                                        //Security.showSettings("2");

                                        mic.setLoopBack(true);

                                        mic.setUseEchoSuppression(true);

                                        //mic.setUseEchoSuppression(true);

                                        // send ALL mic input to the speaker

                                        //mic.setLoopBack(false);

                                        // listen for events

                                        //mic.gain = 40;

                                        //mic.rate = 16;

                                        //mic.setSilenceLevel(5, 1000);

                                        //mic.addEventListener(ActivityEvent.ACTIVITY, onActivityDevice);

                                        enviaStream.attachAudio(mic);

                              }

                              private function onActivityDevice(event:ActivityEvent):void

                              {

                                        trace(mic.activityLevel);

                              }

                              private function capturaCamera():void

                              {

                                        camera = Camera.getCamera();

                                        camera.setMode(200, 150, int(txtFPS.text));

                                        camera.setQuality(0,int(txtQualidade.text));

                                        videoLocal.attachCamera(camera);

                                        enviaStream.attachCamera(camera);

                              }

                              private function onRecebeDados(event:NetStatusEvent):void

                              {

                                        txtOutput.text += 'recebe: ' + event.info.code + "\n";

                              }

                              private function onEnvioDados(event:NetStatusEvent):void

                              {

                                        txtOutput.text += 'envio: ' + event.info.code + "\n";

                              }

                              private function enviaMensagem():void

                              {

                                        var msg:String =  txtNome.text + ':' + txtMensagem.text;

                                        txtHistorico.text += msg  + "\n";

                                        enviaStream.send('recebeMensagem',msg);

                              }

                              public function recebeMensagem(msg:String):void

                              {

                                        txtHistorico.text += msg + '\n';

                              }

                              protected function btnConectar_clickHandler(event:MouseEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        iniciarRecebecimento();

                              }

                              protected function btnEnviar_clickHandler(event:MouseEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        enviaMensagem();

                              }

                              protected function btnCaptura_clickHandler(event:MouseEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        capturaCamera();

                              }

                              protected function button1_clickHandler(event:MouseEvent):void

                              {

                                        // TODO Auto-generated method stub

                                        capturaMic();

                              }

                              protected function selecionarArquivo():void

                              {

                                        fr = new FileReference();

                                        fr.addEventListener(Event.COMPLETE, onCompleteFile);

                                        fr.addEventListener(Event.SELECT, onSelectFile);

                                        fr.browse();

                              }

                              private function onCompleteFile(event:Event):void

                              {

                                        bytes =          fr.data;

                              }

                              private function onSelectFile(event:Event):void

                              {

                                        fr.load();

                              }

                    ]]>

          </fx:Script>

          <fx:Declarations>

                    <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <fx:Style source="defaults.css"/>

          <s:HGroup width="100%" horizontalAlign="center">

                    <s:VGroup width="200" height="100%">

                              <mx:VideoDisplay id="videoLocal" width="200" height="150"/>

                              <s:Button label="Capturar Microfone" click="button1_clickHandler(event)"/>

                              <s:Button label="Enviar Arquivo" icon="selecionarArquivo()"/>

                    </s:VGroup>

                    <mx:VideoDisplay id="videoRemoto" x="169" width="320" height="240"/>

                    <s:TextArea id="txtOutput" width="100%" height="100%"/>

          </s:HGroup>

          <s:HGroup width="100%" height="24">

                    <s:Button id="btnCaptura" label="Capturar Camera" click="btnCaptura_clickHandler(event)"/>

                    <mx:FormItem label="FPS:">

                              <s:TextInput id="txtFPS"/>

                    </mx:FormItem>

                    <mx:FormItem label="Qualidade:">

                              <s:TextInput id="txtQualidade"/>

                    </mx:FormItem>

          </s:HGroup>

          <s:HGroup width="100%" height="25">

                    <s:Label width="100" height="25" text="Nome:" verticalAlign="middle"/>

                    <s:TextInput id="txtNome" width="100%" height="25"/>

          </s:HGroup>

          <s:HGroup width="100%" height="25">

                    <s:Label width="100" height="25" text="FarID:" verticalAlign="middle"/>

                    <s:TextInput id="txtFarID" width="100%" height="25"/>

                    <s:Button id="btnConectar" label=" Conectar FarID" click="btnConectar_clickHandler(event)"/>

          </s:HGroup>

          <s:HGroup width="100%" height="25">

                    <s:Label width="100" height="25" text="NearID:" verticalAlign="middle"/>

                    <s:TextInput id="txtNearID" width="100%" height="25"/>

          </s:HGroup>

          <s:TextArea id="txtHistorico" width="100%"/>

          <s:HGroup width="216" height="23">

                    <s:TextInput id="txtMensagem" width="144"/>

                    <s:Button id="btnEnviar" label="Enviar" click="btnEnviar_clickHandler(event)"/>

          </s:HGroup>

          <s:VGroup width="100%" height="192">

          </s:VGroup>

</s:Application>

Views

384

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines