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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With