0 Replies Latest reply on Oct 12, 2010 12:28 AM by Flex Questions

    Air <-> Java Socket Communication

    Flex Questions


      I use Adobe Air 1.5 with Actionscript 3 to make a socket communication to a Java server application.

      The connection is established and i could send from Air to Java, but sending in the opposite direction failed.

      I also wrote a small Java Client to test the Java Server. The communication worked in both directions and so i,  believe the error should be on air side.

      Currently, both applications running on the same machine.


      Here is the code:

      Air Client:

                     private function start():void
                          _socket=new XMLSocket();
                          _socket.connect("localhost", 9999);
                     private function configureListeners(dispatcher:IEventDispatcher):void
                          dispatcher.addEventListener(Event.CLOSE, closeHandler);
                          dispatcher.addEventListener(Event.CONNECT, connectHandler);
                          dispatcher.addEventListener(DataEvent.DATA, dataHandler);
                          dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
                          dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
                          dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
                     private function closeHandler(event:Event):void
                          trace("closeHandler: " + event);
                     private function connectHandler(event:Event):void
                          trace("connectHandler: " + event);
                     private function dataHandler(event:DataEvent):void
                          trace("dataHandler: " + event);
                     private function ioErrorHandler(event:IOErrorEvent):void
                          trace("ioErrorHandler: " + event);
                     private function progressHandler(event:ProgressEvent):void
                          trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
                     private function securityErrorHandler(event:SecurityErrorEvent):void
                          trace("securityErrorHandler: " + event);


      Java Server

          public void run(){
                ServerSocket server;
                Socket client;
                     server = new ServerSocket(9999);
                          client = server.accept();
                          BufferedReader readerIn = new BufferedReader(new  InputStreamReader(client.getInputStream())); 
                          String str = readerIn.readLine(); 
                          PrintWriter out = new PrintWriter(client.getOutputStream(), true);
                catch(Exception e){
                     logger.error("", e);


      Has anybody an idea what i'm doing wrong?








      After waiting about 30 seconds - 1 minute i get an error:

      securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: app:/main.swf cannot load data from localhost:9999." errorID=0]

      But as you can see, i also tried to load an crossdomain.xml (Security.loadPolicyFile("socket://localhost:8080")) but that also doesn't seemed to work