dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    82

    socket <policy-file-request/>

    I see now that Flash 9 requires a policy file to open a socket connection. I can't find any good material on how to setup this policy file. I don't really want to have to create a seperate server (Java) on port 843 and I've read that you can set one up on the socketing-requesting port (6000 in my case). One site I read (http://www.lightsphere.com/dev/artic...et_policy.html) says to simply reply with the following text:
    "<cross-domain-policy>
    <allow-access-from domain="*" to-ports="*" />
    </cross-domain-policy>"
    I do get the String request "<policy-file-request/>" from the flash client but when I sent that <cross-domain-policy....reply it did nothing. The socket just sits there waiting.
    There other strange thing is that this seems to be a problem with Firefox only. I tried it with IE7 and it makes the request but then keeps on sending/recieving data...even without the policy file reply.
    Anyone know more on this topic and how I can get the FF version to work?
    Thanks in advance.

  2. #2
    Junior Member
    Join Date
    Feb 2009
    Posts
    2

    Java policy-file-request socket response

    I have the exact same problem. The maddening thing is i managed to get this to work a year ago and now that I want to revitalise the project using the same code it doesn't work.

    I get the "<policy-file-request/> from the flash to my java server (flash client opens a socket to my domain to a certain port which im listening for on my java written program running on the server.) I then respond with (Java code)


    policyBuffer.append("<?xml version=\"1.0\"?><cross-domain-policy>");
    policyBuffer.append("<allow-access-from domain=\"*\" to-ports=\"*\" />");
    policyBuffer.append("</cross-domain-policy>");
    String outputmessage = policyBuffer.toString();
    this.output.write(outputmessage);

    this outputs what i assume to be the correct statement from crawling for hours through forums. I had a more specific domain rather than '*' before when it was working but tried to see if * would work because it was more vague. All that happens is that the client disconnects. Before when it was working, the client would open up another connection as normal and say hi.

    I do not want to write any stupid xml config files and just want to respond to the request with the right string. This is the only thing stopping my Flash network game from launching and is driving me nuts knowing that it was working before and some flash update must have f***ed it up.

    An amendment to the code to get this working would be greatly appreciated.

  3. #3
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to have a policy file on the other server or it won't work. Here is more
    http://stunnedgrowth.livejournal.com/4540.html
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  4. #4
    Junior Member
    Join Date
    Feb 2009
    Posts
    2

    I only have the one server

    im hosting the flash swf file, the index page containing the swf, and the Java server program all on one machine. It is annoying that i need this file even though im hosting everything on just the one domain but apparantly you still need it. So i have the one policy file.

  5. #5
    Junior Member
    Join Date
    Nov 2008
    Posts
    1
    I hate reviving old dead threads, but since the internet is filled with posts of confusion based around how to get the cross domain stuff setup when using sockets in flash I figured I'd explain the few notes I've found on the subject here:

    1. All messages are terminated with a null byte. This can be represented in string data by '\0' (without quotes) and then when encoded you will receive a null character. If that does not work, in flash you can use 'writeByte(0)' instead. This is one of the most common issues, so explore this thoroughly before giving up

    2. You have to have something on the server listening for the string '<policy-file-request/>' on socket 843. If it gets that string, respond with your cross-domain xml data. To avoid confusion, when listening for that string just use a 'contains' method rather than an 'equals' to avoid having that null character issue in point 1.

    3. You CANNOT use the crossdomain.xml FILE to communicate over sockets other than 843. This FILE is used only to allow HTTP requests over different ports. For TCP Communication you MUST use a server app that responds with the servers socket policy when prompted over port 843.

    There's a few different server apps that can do what you need them to do. A few people wrote perl scripts that do this, I personally used a C# windows service. In the end, it's not that difficult to setup even if you aren't familiar with socket programming, but this will solve most all the problems people are having.

    Unfortunately, Adobe's documentation doesn't really specify in detail what it is expecting, they just kind of say 'you need a socket policy response' and expect us to know what that is. I hope this helps anyone having this issue.

  6. #6
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    Great Post!

    (I dabble in flash socket connections- java, and phpcli), I remember running into the same issues. Someone in the AS2 form is asking about this, I will point him to this thread!

    Great job again!
    Last edited by guardiankitty; 01-06-2012 at 06:47 PM.

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Posts
    1
    Wow, thank you guys so much!! I took everything you guys said and put the puzzle pieces together, and this is how I got it working:

    1. Listen for the incoming connection and incoming message that says '<policy-file-request/>'
    2. If that message is received, reply with:
    "<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\0";

    Notes:
    - My server script is a PHP script that is listening for socket connections
    - My flash client connects via XMLSocket.
    - I do NOT have a policy file on my server.
    -(I actually had one on there, but it never worked, even specifically loading it with Security.loadPolicyFile("http://domain/crossdomain.xml")
    - I took it off and just used a socket message reply instead, and it works fine.
    - However, I don't know if I will need it for SSL https requests.
    - This should work on any port. I am using port 3333.
    - When replying, as Neox said, make sure you end the outbound message with a null byte: "\0"
    - This should be done for ALL of your messages sent to your flash client.
    - In my PHP script, my output message looks like this: $output = "<?xml version=\"1.0\"?><cross-domain-policy>" . "<allow-access-from domain=\"*\" to-ports=\"*\"/>" . "</cross-domain-policy>" . "\0";

    Sequence of events on Successful Connection:
    - On first connect, your server should receive the message from the client: "<policy-file-request/>"
    - Then, reply with the previous crossdomain output message.
    - The flash client will automatically disconnect, and then immediately reconnect.
    - The connection should now be stable.

    Thanks everyone for all your help, especially sdpagent and neox!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center