1

I am attempting to use TCP Socket from Flash ActionScript. I am using a standard example provided by Adobe. Here is the code:

// Load policy file from remote server.
Security.loadPolicyFile("http://" + serverURL + "/crossdomain.xml");
// Attempt to connect to remote socket server.
try {
    msg("Trying to connect to " + serverURL + ":" + portNumber + "\n");
    socket.connect(serverURL, portNumber);
} catch (error:Error) {
    /*
        Unable to connect to remote server, display error 
        message and close connection.
    */
    msg(error.message + "\n");
    socket.close();
}

My crossdomain.xml file located on port 80:

<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd">
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>

When I load application, I see in my inspector that it accesses the policy file successfully. However Event.CONNECT is never called. I have tried opening various different ports on various domains including same domain with no luck. Tried different policy files.

What am I missing?

1

2 Answers 2

2

If the allowscriptaccess is false you won't be able to bypass that so what you are missing is the adobe policy server.

http://vvowproject.googlecode.com/svn-history/r41/trunk/server/flashpolicyd.py

On the server open port 843 then use this command

sudo ./flashpolicyd.py --file=crossdomain.xml --port=843

here is the crossdomain.xml

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>

This will definitely work, i tried it myself with your example.

Sign up to request clarification or add additional context in comments.

1 Comment

What mislead me is that flash opens crossdomain.xml from port 80.
1

This is what I know from using TCP/IP Sockets and XML. I've set up a Ruby server with a Flash client successfully, but want to know more about chat servers. I hope some of this is helpful.

You need a Daemon with Flash AS3. Here's the documentation.
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000318.html

alt text http://www.ashcraftband.com/myspace/videodnd/daemonLil.jpg

To create a socket connection, you must create a server-side application to wait for the socket connection request and send a response to the SWF file. This type of server-side application can be written in a programming language such as Java, Python, or Perl. To use the XMLSocket class, the server computer must run a daemon that understands the protocol used by the XMLSocket class. The protocol is described in the following list:

• XML messages are sent over a full-duplex TCP/IP stream socket connection.
• Each XML message is a complete XML document, terminated by a zero (0) byte.
• An unlimited number of XML messages can be sent and received over a single XMLSocket connection.

Understanding the security changes in Flash Player 10
http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html


XML SECURITY POLICY

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="SOAPAction"/>
</cross-domain-policy>

FLASH CLIENT
Remember to set Publish Settings to Access Network Only.

SERVER
Open a separate port for security policy, and keep it running in the background.

3 Comments

@Quambar Raza Seems you are knowledgeable in this SOCAT/Flash area... can you help my post out with an answer? stackoverflow.com/questions/54974902/…
sorry mate, its been a while since i looked into this, but from what i can recall adobe policy server was the most important bit to handle the CORS, without that you can't communicate with the flash server.
Well it was worth a shot! I have literally been trying to get my thread to work for almost 2 weeks now. I -believe- I got the policy server set up correctly... (test via command line at least).. not sure if Flash app is getting it though? I just cant get my flash app to connect to SOCAT instance that is getting the data on ttyUSB0. Just fails to connect. Thanks for the reply! If you get an idea, PLEASE post it in my thread linked to above (I outline all my steps.. maybe I missed something?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.