5
votes

This problem is driving me crazy! I've read all the questions on Stack Overflow but I'm still stuck.

My as3 program works very well, but when I have finished it and put it on a server, it starts to request this famous policy file.

AS3 script:

socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);

socket.connect( MYHOST, 4242 );

C# server code:

TcpListener serverSocket = new TcpListener(4242);
TcpClient clientSocket = default(TcpClient);
serverSocket.Start();
clientSocket = serverSocket.AcceptTcpClient();
NetworkStream networkStream = clientSocket.GetStream();
StreamReader read = new StreamReader(networkStream, Encoding.UTF8);
StreamWriter write = new StreamWriter(networkStream, Encoding.UTF8);

response = read.ReadLine();

if (response.Contains("policy"))
{
 write.Write("<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>\0");
 write.Flush();
 clientSocket.Close();
 return;
}

So, when the AS3 doesn't find the policy on the default port 843 (or something similar), it asks directly on the same socket as the connection. My C# code sees the request and replies, after which the AS3 script closes the connection (which is OK), but it never reconnects.

I have tried to put this in the AS3 before the connect():

Security.loadPolicyFile( "xmlsocket://myhost.com:4242");

But when I do the connect() it simply gets stuck and never requests the policy file. After I close the AS3 application, my server sees the request, but the connection is closed. It's like the client forget to do a flush.

Can someone tell me how I can solve this problem correctly?

2
Do you try to turn on the flash player policy log, I think it may help to clarify what is going on. To turn policy log on you need the debug version of flash player and mm.cfg file in your home directory with flag PolicyFileLog set to 1. - fsbmain
Thanks for your reply, but i have a problem. I dont know wich package i must download!! I have windows 7 and there arent downloads for it! - Univers3
Windows Flash Player 11.7 ActiveX control content debugger (for IE) Windows Flash Player 11.7 Plugin content debugger (for Netscape-compatible browsers - FireFox and Chrome (but for Chrome you have to disable native paper plugin) Windows Flash Player 11.7 Projector content debugger (for debug without browser) - fsbmain

2 Answers

6
votes

After 3 days i have finally discovered what is the bug in the code.

A bounty of 50 points and no one have noticed it :-(

Is very stupid, a novice error:

When the flash application ask for the policy file dont send the newline char, but the terminating char '\0'.

and im reading with the read.ReadLine(); that read until the '\n', so it stuck.

Thank you all for your replies.

0
votes

I've faced a problem similar to your's. The fact is, that while running a Flash app into a C#, it lose lot's of requests which port differs from standart. The solution is not to use such requests in Flash. So you have to put them into C#, and call this functions with Flash's ExternalInterface.call. When the request is completed, your C# must call a Flash function, passing req's answer as a parameter.