5 Replies Latest reply on Oct 29, 2010 4:50 AM by Claudiu Ursica

    Android Hero denies XMLSocket or Socket connection? ....errors #2031, #2048

    Claudiu Ursica Level 4

      I am trying to adapt an existing flash web chat application for the Android mobile phone and I am having this really annoying issue. The server is a custom based solution and can send back both binary messages or XML. So I can use either XMLSocket class or the Socket class to get data from the server. Everything works fine when deployed and I connect from the desktop but when I try it from the android mobile I get the infamous errors #2031, followed by #2048. Now the crossdomain.xml file is rock solid and works well for desktop. When the connect socket method runs I see that the server replies with the crossdomain file but I get the error when running on the mobile. Has anyone bumped into this? Is there some limitation from the mobile phone part. I wasn't able to find anything relevant for this issue, in terms of the phone not allowing Socket or SMLSocket connections.

      The phone runs Android 2.1 and indicates the FL10,1,123,358 version of flash. The issue can be reproduced also on the HTC Desire.

      Any input on this would be highly appreciated...

        • 1. Re: Android Hero denies XMLSocket or Socket connection? ....errors #2031, #2048
          Sudheendra Sathavalli Level 1

          Error #2031 refers to Socket error , which might be due to the port 8080 conflict  in which case you have to set another port for it. and error 2048 is sandbox violation which is like it cant access the data of that particular folder as it is not Trusted . So can you please post the code so that i can compile it and run the swf on My HTC hero.





          • 2. Re: Android Hero denies XMLSocket or Socket connection? ....errors #2031, #2048
            Claudiu Ursica Level 4

            Code is really standar Socket start connection code.


            Jusdt have a flash file and add a button named connect, a textfield called output and 2 more text inputs for the ip and port. The rest is in this snippet:


                import flash.display.Sprite;
                import flash.events.Event;
                import flash.events.IOErrorEvent;
                import flash.events.MouseEvent;
                import flash.events.SecurityErrorEvent;
                import flash.net.URLLoader;
                import flash.net.URLLoaderDataFormat;
                import flash.net.URLRequest;
                import flash.net.URLRequestMethod;
                import flash.events.*;
                import flash.net.Socket;
                import flash.system.Security;
                import flash.system.Capabilities;
                import flash.utils.ByteArray;
                import flash.net.Socket;
                public class fc extends Sprite
                    import flash.text.TextFormat;
                    private var newFormat:TextFormat = new TextFormat();
                    private var chatSocketConnection:Socket = new Socket();
                    public function fc()
                        connect.addEventListener(MouseEvent.CLICK, onClick);
                        chatSocketConnection.addEventListener(Event.CONNECT, connectHandler);
                        chatSocketConnection.addEventListener(Event.CLOSE, closeHandler);
                        chatSocketConnection.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
                        chatSocketConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
                        chatSocketConnection.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
                        newFormat.font = "Arial";
                        newFormat.bold = true;
                        newFormat.size = 30;
                        newFormat.color = "0xCC0000";
                        output.setStyle("textFormat", newFormat);
                        connect.setStyle("textFormat", newFormat);
                        send.setStyle("textFormat", newFormat);
                        ip.setStyle("textFormat", newFormat);
                        port.setStyle("textFormat", newFormat);
                    private function onClick(event:MouseEvent):void
                            chatSocketConnection.connect(ip.text, int(port.text));
                        catch (e:*)
                            output.appendText("Error" + e + "\n");
                    private function connectHandler(event:Event):void
                        output.appendText("Connected" + "\n");
                    private function securityErrorHandler(e:SecurityErrorEvent):void
                        output.appendText("SecurityError " + e.text +  "\n");
                    private function errorHandler(e:IOErrorEvent):void
                        output.appendText("IOerror " + e.text + "\n");
                    private function closeHandler(event:Event):void
                        output.appendText("Socket closed" + "\n");


                    private function socketDataHandler(event:ProgressEvent):void
                        output.appendText("Got Socket Data Data" + "\n");
                    private function ioErrorHandler(event:IOErrorEvent):void
                        output.appendText("Socket IOError: " + event.text + "\n");




            • 3. Re: Android Hero denies XMLSocket or Socket connection? ....errors #2031, #2048
              Claudiu Ursica Level 4

              I forgot about this it was not suppose to work in the first place, but  the the phone which had an experimental PROM, and the guy who was  upgrading the phone kindly forgot to mention the expoerimental part. So  I'm marking this as solved.



              • 4. Re: Android Hero denies XMLSocket or Socket connection? ....errors #2031, #2048
                Grax Bishop

                Hi there Claudiu,


                I've been having some problems with connecting to sockets via Actionscript on an Android phone.


                What I have is a simple Android app wrapper over a browser. Then this browser embeds the swf, which I am using to send out socket commands. I want to send out socket commands to the Android app itself so that it can do things. So I am connecting to "localhost". Everything works as expected when I am in the Flash IDE.


                However when I try make a socket connection I get the #2048 security error. I suspect it's got something to do with security policies and cross-domain xmls needing to be imported in but I'm not sure how to go about this.


                I wanted to ask if you had any success. You said that you're marking this as solved. Is that because you had the ActionScript connecting to socket on Android is no errors, or is it solved because it's not possible to send socket commands in an Android device?


                Any help would be greatly appreciated.


                Thanks in advance.

                • 5. Re: Android Hero denies XMLSocket or Socket connection? ....errors #2031, #2048
                  Claudiu Ursica Level 4

                  Well I had the crossdomain in place I tripplec checked that. My case was that I

                  had no idea that the phone was messed with, so it showed me a FP 10 but it was

                  some experimental upgrade made to the phone. Funny thing URLLoader requests went

                  through just fine. I ran the same code on an HTC Desire and I had no issue with

                  that... We were sniffing packets over the network it seemed that the call for

                  the crossdomain got to the server but the reply never got back. I read something

                  about latency and somehow the response being delayed for moreover that a sec for

                  some phones but I doubt that was the issue here. The phone had its limitations I

                  guess, after downgrading it back to original settings we were not able to do

                  much on it anyway. Sorry I can't help more with this... I guess sockets are only

                  working for Desire and not for Hero.