13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Security<br />

A socket policy file has the same syntax as a URL policy file, except that it must also specify the ports to which it grants<br />

access. Wh<strong>en</strong> a socket policy file is served from a port number below 1024, it may grant access to any ports; wh<strong>en</strong> a<br />

policy file comes from port 1024 or higher, it may grant access only to ports 1024 and higher. The allowed ports are<br />

specified in a to-ports attribute in the tag. Single port numbers, port ranges, and wildcards<br />

are accepted values.<br />

Here is an example socket policy file:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

To retrieve a socket policy file from port 843 or from the same port as a main socket connection, call the<br />

Socket.connect() or XMLSocket.connect() method. Flash Player first checks for a master policy file on port 843.<br />

If it finds one, it checks to see if the file contains a meta-policy statem<strong>en</strong>t that prohibits socket policy files on the target<br />

port. If access isn’t prohibited, Flash Player first looks for the appropriate allow-access-from statem<strong>en</strong>t in the<br />

master policy file. If it doesn’t find one, it th<strong>en</strong> looks for a socket policy file on the same port as the main socket<br />

connection.<br />

To retrieve a socket policy file a differ<strong>en</strong>t location, first call the Security.loadPolicyFile() method with the special<br />

"xmlsocket" syntax, as in the following:<br />

Security.loadPolicyFile("xmlsocket://server.com:2525");<br />

Call the Security.loadPolicyFile() method before calling the Socket.connect() or XMLSocket.connect()<br />

method. Flash Player th<strong>en</strong> waits until it has fulfilled your policy file request before deciding whether to allow your main<br />

connection. However, if the master policy file specifies that the target location can’t serve policy files, the call to<br />

loadPolicyFile() has no effect, ev<strong>en</strong> if there is a policy file at that location.<br />

If you are implem<strong>en</strong>ting a socket server and you need to provide a socket policy file, decide whether to provide the<br />

policy file using the same port that accepts main connections, or using a differ<strong>en</strong>t port. In either case, your server must<br />

wait for the first transmission from your cli<strong>en</strong>t before s<strong>en</strong>ding a response.<br />

Wh<strong>en</strong> Flash Player requests a policy file, it always transmits the following string as soon as a connection is established:<br />

<br />

Once the server receives this string, it can transmit the policy file. The request from Flash Player is always terminated<br />

by a null byte, and the response from the server must also be terminated by a null byte.<br />

Do not expect to reuse the same connection for both a policy file request and a main connection; close the connection<br />

after transmitting the policy file. If you do not, Flash Player closes the policy file connection before reconnecting to set<br />

up the main connection.<br />

Last updated 6/6/2012<br />

1058

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!