Skip to main content
Participant
May 22, 2011
Question

Very strange problem with UDP socket on Mac

  • May 22, 2011
  • 1 reply
  • 1301 views

Hi,

I'm trying in vain to make PHP and an AIR app communicate using UDP Socket (in multicast using 225.0.0.0). My PHP script must be sending some data to my AIR app. I choose the port 60000 for this. I also wrote a tiny C program that listen to the same port (I know that 2 programs can't bind to the same port simultaneously). The 3 programs are one the same machine, Mac OS X 10.6.7, Flash Builder 4.5, Air 2.6 and XCode 4.0.

**** Scenario #0 : (what I originally wanted to do)

- I launch the AIR app, listening to the port 60000

- I launch my PHP script sending some data

=> nothing is received, the DatagramSocketDataEvent.DATA is never called

**** Scenario #1

- I launch the AIR app, listening to the port 60000

- I launch my C program (XCode) listening to the SAME port, without any complain !!!

- I launch my PHP script, and it works, the AIR app receives what was send (and the C program too).

**** Scenario #2

- I launch the AIR app, listening to the port 60000

- I launch my C program (XCode) listening to another port.

- I launch my PHP script, and it works, the AIR app receives what was send.

*** Scenario #3

- I launch my C program listening to the port 60000

- I launch my AIR app, it complains that the port 60000 is already in use !

I don't have any explanation. Do you have some ?

My Flex Code :

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

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

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

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

     <fx:Declarations>

     </fx:Declarations>

     <fx:Script>

          <![CDATA[

               import flash.events.DatagramSocketDataEvent;

               import flash.net.DatagramSocket;

              

               import mx.controls.Alert;

               private var socket:DatagramSocket;

              

               public function creationCompleteHandler(event:MouseEvent):void {

                    socket = new DatagramSocket();

                    socket.addEventListener(DatagramSocketDataEvent.DATA,dataReceived);

                    socket.addEventListener(IOErrorEvent.IO_ERROR,IOErrorHandler);

                    socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler);

                    socket.bind(60000,"225.0.0.0");

                    socket.receive();

                    Alert.show(socket.localAddress.toString()+' '+socket.localPort.toString());

               }

              

               public function IOErrorHandler(event:IOErrorEvent):void {

                    Alert.show("IOError");

               }

              

               public function securityErrorHandler(event:SecurityErrorEvent):void {

                    Alert.show("Security Error");

               }

              

               public function dataReceived(event:DatagramSocketDataEvent):void {

                    data.text = event.toString();

               }

              

               public function Envoyer(event:MouseEvent):void {

                    var loader:URLLoader = new URLLoader();

                    var request:URLRequest = new URLRequest("http://127.0.0.1/~william/panoramatch/data.php");

                    var variable:URLVariables = new URLVariables();

                    variable.commande = "scoreA";

                    variable.valeur = score.text;

                    request.method=URLRequestMethod.POST;

                    request.data = variable;

                   

                    loader.load(request);

               }

              

               public function envoyerUDP(event:MouseEvent):void {

                    var data:ByteArray = new ByteArray;

                    data.writeUTFBytes(score.text);

                   

                    socket.send(data,0,data.length);

                   

               }

          ]]>

     </fx:Script>

     <s:Button x="10" y="40" label="Envoyer" click="Envoyer(event);"/>

     <s:TextInput x="10" y="10" id="score"/>

     <s:TextArea x="10" y="69" width="456" editable="false" id="data"/>

     <s:Button x="88" y="40" label="Bind" click="creationCompleteHandler(event)"/>

     <s:Button x="166" y="40" label="Envoyer UDP" click="envoyerUDP(event)"/>

</s:WindowedApplication>

This topic has been closed for replies.

1 reply

June 25, 2011

Hi Awebteacher,

I am running into the exact same problem. I used the UDP example from the Adobe site, and wrote a second listener in Processing to listen to the same port just to make sure there are UPD data coming. I tried all your scenarios and had the same result. It seems like when running the Processing sketch, or your C program, somehow it enables the Adobe AIR to listen to the port... All I can think about is this might be a Adobe 2.0 security issue? If you had answer already please enlighten me. This is bothering me....