6 Replies Latest reply on Mar 11, 2010 12:37 AM by gaurav_ch

    need help with Error #2044: Unhandled securityError:.

    gaurav_ch

      Hi,

       

      I am developing an AIR+AJAX app and I am using sockets to connect to the ftp server and just checking whether the app is able to connect to the ftp server successfully, check the user name and password and return with a message.

       

      It connects and displays the following error after 15 seconds or so:

       

      Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: app:/index.html cannot load data from www.mydomain.in:21.

      at flash.html::HTMLLoader/nativeOnMouseUp()

      at flash.html::HTMLLoader/invokeMouseUpImpl()

      at flash.html::HTMLLoader/onLeftMouseUp()

       

       

      How can I take care of this? The app needs to connect to the ftp server often. This error is shown when I am in preview mode.

       

      This is absolutely essential for me to take care of this because the app will check any number of domains and connect using sockets. Is there anyway to suppress these errors. I have heard of air.Security but how exactly should I use in this regard.

       

      Please help.

       

      Gaurav

        • 1. Re: need help with Error #2044: Unhandled securityError:.
          Horia Olaru Adobe Employee

          Hi Gaurav,

           

           

          I have a few questions:

           

          Could you provide a sample application, or some sample code that exemplifies this error?

           

          What is the version of AIR that you are using?

           

          What do you mean by "preview mode"?

          Do you mean you are running the application using adl / the AIR SDK?

           

           

          Thank you,

          Horia

          • 2. Re: need help with Error #2044: Unhandled securityError:.
            gaurav_ch Level 1

            Hi Horia,

             

            Thanks a lot for replying. I am glad atleast somebody did. To answer your questions:

             

            1) Could you provide a sample application, or some sample code that exemplifies this error? - I am attaching the code. Its using sockets:

             

            var s = new air.Socket("www.domain", 21); 
            
            s.addEventListener(air.ProgressEvent.SOCKET_DATA, sOk); 
            s.addEventListener(air.Event.CONNECT, sData);
                 
            function sOk(){ 
                 var d = s.readUTFBytes(s.bytesAvailable); 
                 window.alert(d); 
            }  
            function sData(){ 
                 s.writeUTFBytes("USER username\n"); 
                 s.writeUTFBytes("PASS password\n"); 
                 s.writeUTFBytes("QUIT\n");
                 s.flush();     
            }
            

             

            2) What is the version of AIR that you are using? - 1.5.3

             

            3) What do you mean by "preview mode"? - I am using DW CS4 and I am previewing by pressing ctrl+shift+f12 key.

             

            This error is related to flash player because it shows not only in preview mode but also when I install an air file.

             

            I don't know how to suppress this error. I just need to check that the domain, user name and password supplied by the user is correct and able to connect to the ftp server.

             

            What strange is this error in not shown immediately but after 15 to 20 seconds after the app connects to the server.

             

            I read about crossdomain.xml but I cannot use this as the server will be different for each user. I cannot go on asking the user to put a crossdomain.xml file in their server before they even check.

             

            This is something I need to correct asap as this app will be going to production soon.

             

            Please help.

             

            Gaurav

            • 3. Re: need help with Error #2044: Unhandled securityError:.
              Horia Olaru Adobe Employee

              Hi Gaurav,

               

               

              When running the provided sample, before the securityError I get an IOErrorEvent.

              Error #2044: Unhandled IOErrorEvent:. text=Error #2031: Socket Error.
                   at ResourceLoader/nativeReceivedAllData()
                   at ResourceLoader/receivedAllData()
                   at ResourceLoader/onComplete()
              

               

              Do you get this error as well? If so, read below.

               

               

              This IOErrorEvent is dispatched because the site in question does not listen on port 21.

               

              So, the first issue would be that the host:port you're trying to connect the Socket to are invalid. You can always do a manual test to see if a ftp site is valid by pasting host:port in Firefox. ("telnet host port" is another, more generic option)

               

              You should treat this by listeneing for the air.IOErrorEvent.IO_ERROR.

               

              The securityError event appears in conjunction with the ioError. The 15-20 second until the event is fired, is the default timeout for the socket connection. If the connection succeeds, no error event will be thrown.

               

              The securityError event should not be dispatched in the case of AIR application sandbox content. This is not expected behavior,  and it will be fixed in AIR 2.

               

              To work around the SecurityError dialog, listen for the securityError event and ignore it, while treating the connection error in the IOErrorEvent handler.

               

               

              s.addEventListener(air.SecurityErrorEvent.SECURITY_ERROR, function(ev) { air.trace(ev); });

               

               

              As I've mentioned before, this issue is fixed in AIR 2. If you want to give the AIR 2.0 beta 2 a try, it is publicly available (along with the DW extension) at:

              http://labs.adobe.com/downloads/air2.html

               

               

              Please let me know if this solves the issue you are having!

               

               

              Thank you,

              Horia

              1 person found this helpful
              • 4. Re: need help with Error #2044: Unhandled securityError:.
                gaurav_ch Level 1

                Hi Horia,

                 

                THANKS THANKS THANKS THANKS.

                 

                1) The event listener you asked me to use solved the problem of showing the error in preview and installed mode. Thanks a bunch.

                 

                2) I was getting the IO error as you mentioned but not every time. It used to spring off and on but I thought that there is some problem with my code. If I modify that code it used to stop showing but after 2 or 3 previews again it used to show.

                 

                I will give AIR 2 a try. Thanks for pointing me to the right resource.

                 

                One more request - can you point me to a book or online documentation for AIR+AJAX where all these event listeners etc are explained? Because the book I have and the live docs are not so exhaustive and I missed these type of listeners. Also, I am not able to upload a file using FTP STOR command I see that I need to use some kind of Byte array. The docs are not helping me. So, a reliable source for complete reference would really help me.

                 

                Thanks a lot again.

                 

                Gaurav

                • 5. Re: need help with Error #2044: Unhandled securityError:.
                  Horia Olaru Adobe Employee

                  Hi Gaurav,

                   

                   

                  I'm not sure exactly what kind of documentation you are looking for.

                   

                  The live docs language reference pages have sections for Events and Error for each API. You can see there what events or errors a class or any given function may dispatch, and treat them accordingly.

                  (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html)

                   

                  Here is a resource on error events for ActionScript:

                  http://livedocs.adobe.com/flex/3/html/help.html?content=11_Handling_errors_10.html

                   

                  I don't know if you're aware of this, but even if an AS3 API does not have an alias in AIRAliases, it can still be accessed via the runtime property:

                  runtime.<package-name>.<class/function> (ex. runtime.flash.events.ErrorEvent)

                   

                  You might want to also have a look at this book:

                  http://onair.adobe.com/files/AIRforJSDevPocketGuide.pdf

                  See the Troubleshooting AIR Applications section (and the "Missing event listeners for error events" subsection)

                   

                   

                  Regarding the file upload.

                  I think the FileStream is the API you are looking for.

                  The live docs for FileStream should have pretty good examples on reading from a file. I think the 'readBytes' function is the one you should be looking at.

                   

                  The above book contains a File API section - you can look at "Asynchronously Read Text from a File" for a streamlined file reading process.

                  You will probably want to read binary files, but the process is similar. Subsitute the 'readMultiByte' function, which returns a string, with the 'readBytes' function, which reads binary data into a ByteArray.

                   

                  You will then write the data read into the byte array to the socket.

                   

                  Also, there is a sample on Adobe Labs called KeePIPE, demonstrating the use of new networking APIs in AIR 2. It might be too complicated, and not map exactly to what you're looking for, but you can have a look at:

                  js/SendChannel.js : App.SendChannel.prototype.sendFile function.

                  Source Code: http://download.macromedia.com/pub/labs/air/2/b2/samples/keepipe.zip

                  Samples Page: http://labs.wip3.adobe.com/technologies/air2/samples/

                   

                   

                  Hope this helps.

                   

                  Horia

                  • 6. Re: need help with Error #2044: Unhandled securityError:.
                    gaurav_ch Level 1

                    Thanks Horia. I really am grateful for all the help. I will keep this thread alive with updates.

                     

                    Gaurav