• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

Actionscript Socket Policy File

Hi,

I have created XML file as the following:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
&#9;<allow-access-from domain="localhost" />
</cross-domain-policy>

Open in new window


And add the following code at the beginning of the actionscript:
Security.loadPolicyFile("http://localhost/socketpolicy.xml");
Security.allowDomain("*");

Open in new window


The socket connect to the server and ask for the policy file and disconnect.
How can I fix that?
0
Mohamed Abowarda
Asked:
Mohamed Abowarda
  • 10
  • 8
1 Solution
 
dgofmanCommented:
What the webserver and language are u using on backend? Java to  XMLSocket?
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
I am using Flash Actionscript, (No Java).

Class: Socket
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dgofmanCommented:
If not Java what language are you using for creating socket with backend?
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
@dgofman: Please read my post http:#35494088

I am using Actionscript.
0
 
dgofmanCommented:
Do you want to tell me your are connecting from one ActionScript to another ActionScript? :)
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
@dgofman: No, I have a server I made in C# and want to the website visitors to connect to that server using flash after the page load.
0
 
dgofmanCommented:
By the way modify your crossdomain.xml file with new format

<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*"/>
<allow-http-request-headers-from domain="*" headers="*" secure="true"/>
</cross-domain-policy>


Also open browser and try to get XML file from your local machine from remote host

http://remotehost.domain.com/crossdomain.xml
0
 
dgofmanCommented:
You must copy crossdomain.xml file on your C# host (IIS Server root C:\Inetpub\wwwroot)

Validate from the browser if you can reach this file
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
Currently, I am using C# just to test on Windows XP.
0
 
dgofmanCommented:
fine test on local box, by the way are you using Flex Builder Premium?
If Yes, disable "Network Monitoring" tool
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
I am only using Flash CS 5, Actionscript 3.0 and Flash Player 10.
0
 
dgofmanCommented:
Should not be problems in your case
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
It still asking me for the policy file even after I added it at public_html "www".

Any suggestions?
0
 
dgofmanCommented:
Can you provide snippet code of your Socket ActionScript implementation?
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
The following code work perfect after I compile it to EXE, or debug it using flash, when I try to use it on http://localhost it connect to the server and ask for the policy file even after I added the line Security.loadPolicyFile("http://localhost/crossdomain.xml");
import flash.net.Socket;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.utils.ByteArray;
import flash.system.Security;

Security.loadPolicyFile("http://localhost/crossdomain.xml");

var socket:Socket = new Socket();
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onDataArrived);
socket.connect("localhost", 10000);

stop();

// Code here to handle the events...

Open in new window

0
 
dgofmanCommented:
I didn't have experience writing socket using C#, but I can tell you how I implemented for Java servlets.

Cross domain policy working differently if you are using Web Hosting and Socket. When request coming to the server from AS Socket we are not loading crosddomain.xml file from a virtual domain.

So, you line Security.loadPolicyFile("http://localhost/crossdomain.xml"); will not work at that time, you
need create stream response on first request string "<policy-file-request/>"

Check this link:

http://stackoverflow.com/questions/1409771/c-socket-policy-file-server-for-low-level-as3-0-socket-connections


In my Java code I handle like this:


private void readRequest() throw Exception{
      while (!_socket.isClosed()){
            StringBuffer buffer = new StringBuffer();
            int length = _socketIn.available();
            for(int i = 0; i < length; i++){
                  int charCode =  _socketIn.read();
                  if(charCode != 0) buffer.appendCodePoint(charCode);
            }
            final String request = buffer.toString();
            if(request.equals("<policy-file-request/>")){
                  StringBuffer policyBuffer = new StringBuffer();
                  policyBuffer.append("<?xml version=\"1.0\"?><cross-domain-policy>");
                  policyBuffer.append("<allow-access-from domain=\"*\" to-ports=\"*\" />");
                  policyBuffer.append("</cross-domain-policy>"
                  write(policyBuffer.toString());
            }else{
                  //HANDLE OTHER REQUESTS
            }
      }
}

0
 
dgofmanCommented:
Another example:

http://stackoverflow.com/questions/2855046/problem-with-socket-communication-between-c-and-flex

So, your Google search keywords should be:

C# socket <policy-file-request/>
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
Thank you,
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now