4 Replies Latest reply on Jul 23, 2008 3:51 PM by jylaxx

    sockets bug

    TangoFoxtrot
      There is an issue, I'd say a bug - if I'm wrong please correct me - with sockets in Flash Player 9. I am using debug version 9.0.124.0 on Windows XP, normal player is affected too. Problem is, the player doesn't wait for completion of downloading of a policy file, even though the documentation says so:

      "When considering a request that requires a policy file, Flash Player or AIR always waits for the completion of any policy file downloads before denying a request."
      http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/system/Security.html#loadP olicyFile()

      To demonstrate this one has to put some effort into setup, I think it's easiest by having personal firewall ask user for permissions for [some] outgoing connections, which has an effect of puting them "on hold". During this time Flash Player waits 3 seconds for a policy file, BUT PROGRAM FLOW DOES NOT STOP. The result: socket tries to connect and fails to do so.

      In debug log it looks like this:

      OK: Root-level SWF loaded: http://localhost/flash/socketdemo.swf
      OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://adobe.com:1234 by requestor from http://localhost/flash/socketdemo.swf

      (pause)

      Warning: Timeout on xmlsocket://adobe.com:843 (at 3 seconds) while waiting for socket policy file. This should not cause any problems, but see http://www.adobe.com/go/strict_policy_files for an explanation.
      Warning: Timeout on xmlsocket://adobe.com:1234 (at 3 seconds) while waiting for socket policy file. This should not cause any problems, but see http://www.adobe.com/go/strict_policy_files for an explanation.
      Error: Request for resource at xmlsocket://adobe.com:1234 by requestor from http://localhost/flash/socketdemo.swf has failed because the server cannot be reached.

      Of course in this case the target port 1234 isn't listening, but that's not the point. The crucial point is that the PROGRAM DOESN'T WAIT AT ALL, CONNECTION FAILURE CAN BE SEEN IN A BLINK OF AN EYE (use the attached Flex script), not after 3 seconds.

      The real problem is that EVEN WHEN THE POLICY FILE IS AVAILABLE AND IT APPROVES ALL CONNECTIONS, THE PLAYER DOESN'T CONNECT TO A TARGET PORT. I think reason for that is the issue described above.

      The problem is similar to the behaviour of alert(), which doesn't wait for a user to click a button. But alert can be given an event handler, is there an "policy file download complete" event?

      http://flexed.wordpress.com/2006/08/04/alertshow-behavour-in-flex/


      Here's an example Flex script, compile with

      mxmlc --file-specs socketdemo.mxml

      and put it in a stock html page, open in a browser.

      ---

        • 1. Re: sockets bug
          jylaxx Level 1
          I am using socket with Flex and be sure there is no issue.
          Timeout is on the connection : once the socket is connected, it is waiting for the data.
          If there is no listening port why do you want to wait for ?
          • 2. Re: sockets bug
            jylaxx Level 1
            BTW you must listen to SecurityErrorEvent and to connect event.
            So your code is wrong as you test the connected property just after the connect call.
            You must wait for the connect event or an error event.
            Call to connect is not blocking !!
            Think asynchronous +++
            • 3. Re: sockets bug
              TangoFoxtrot Level 1
              Thanks jylaxx. I was hoping silently that this was an error in my thinking and not a bug, it's sure faster to fix. I changed the code a bit and was able to connect. The bit I was missing is that connect() is asynchronous so I was testing socket for being connected to early.

              How (and to what) do I attach an event handler for SecurityErrorEvent?
              • 4. Re: sockets bug
                jylaxx Level 1
                This event can help to detect security policy error. Use as ioError.

                quote:

                securityError:SecurityErrorEvent — Dispatched if a call to Socket.connect() attempts to connect to either a server outside the caller's security sandbox or to a port lower than 1024. (This restriction is not placed on AIR content running in the application security sandbox.) You can work around either problem by using a cross-domain policy file on the server. For more information, see the "Flash Player Security" chapter in Programming ActionScript 3.0.