After Adobe Flash Player is upgraded to 9.0.124, the security policy loading methods in the original socket or xmlsocket applications cannot be used due to security policy changes. The changes are as follows:
1. First, check whether port 843 of the target server provides a security policy.
2. If 1 does not detect the policy, check whether the security. loadpolicyfile (xmlsocket: //) method is used to provide the security policy. If not, use step 1.
3. Check whether the target port of the target server provides a security policy.
Before proceeding to the specific processing method, I will first describe the Flash Player verification process. Before the flex program sends a socket or xmlsocket (hereinafter referred to as a socket) request, flash player will first determine whether the request is a local call, if not. You can use a socket to link to your server. After the three-way handshake is successful, you can send the string "<policy-file-Request/> \ 0" and then listen to the returned security policy. After receiving the Security Policy, flashplayer disconnects the verified socket and then runs the socket of the program. During the entire SWF operation, no matter how many requests you request, Flash Player only verifies the same domain once. There are two key points here,
The first one is the verified socket and the program socket are two sockets. Therefore, when you perform a local test, the server listens to N socket requests, but is assigned to the server, the server listens to n + 1 requests.
The second is to verify that the socket sends the <policy-file-Request/> \ 0 "request and receives your policy file in no particular order, therefore, you do not need to send the policy file after "<policy-file-Request/> \ 0" is received. My approach is to send the policy string as long as the request is monitored.
The preceding three methods are provided to handle security policies. The solution is similar, that is, to require the server to listen to a port. If the client sends a "<policy-file-Request/> \ 0" request, the server returns the string of your security policy.
In fact, the main difference between the three processing methods is the listening port. Methods 1 and 2 require listening on another port, and the third is listening on the port of the application itself. In fact, the number of listening ports is less than one. No more in the virtual space. The port does not mean listening when listening, but permission is required. Even if you have the permission to listen, the firewall must agree. So I prefer the third one.
Below is my test server code (C #)
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. net. Sockets;
Using system. net;
Using system. xml;
Namespace Server
{
Class Program
{
Static void main (string [] ARGs)
{
Try
{
Int Port = 60002;
String host = "192.168.1.103 ";
IPaddress IP = IPaddress. parse (host );
Ipendpoint IPE = new ipendpoint (IP, Port );
Socket S = new socket (addressfamily. InterNetwork, sockettype. Stream, protocoltype. TCP); // create a socket class
S. BIND (IPE );
S. Listen (0 );
Console. writeline ("Wait For connect 60002 ");
While (true)
{
Try
{
Socket temp = S. Accept (); // create a new socket for the new connection.
Console. writeline ("Get a new connect" + datetime. Now. tostring ());
String recvstr = "";
Byte [] recvbytes = new byte [1, 1024];
Int bytes;
Bytes = temp. Receive (recvbytes, recvbytes. length, 0); // receive information from the client
Recvstr + = encoding. getencoding ("UTF-8"). getstring (recvbytes, 0, bytes );
Console. writeline ("Server get message: {0}", recvstr); // display information sent from the client
If (recvstr = "<policy-file-Request/> \ 0 ")
{
String sendstr = "<cross-domain-Policy> <allow-access-from domain = \" 192.168.1.102 \ "to-ports = \" 60000-60010 \ "/> </Cross-Domain -Policy> \ 0 ";
Byte [] BS = encoding. getencoding ("UTF-8"). getbytes (sendstr );
Temp. Send (BS, BS. length, 0); // return the client success message
Console. writeline ("Send:" + sendstr );
// Temp. Close ();
// S. Close ();
}
Else
{
String sendstr = "OK! Client send message sucessful! ";
Byte [] BS = encoding. getencoding ("UTF-8"). getbytes (sendstr );
Temp. Send (BS, BS. length, 0); // return the client success message
// Temp. Close ();
// S. Close ();
}
}
Catch (exception ex)
{
Console. writeline ("socketexception: {0}", ex );
}
}
}
Catch (exception ex2)
{
Console. Write (ex2.message. tostring ());
}
}
}
}
The server receives a new connection and receives the message "<policy-file-Request/>, after the server responds, it sends "<cross-domain-Policy> <allow-access-from domain = \" 192.168.1.102 \ "to-ports = \" 60000-60010 \ "/> </cross- domain-Policy> \ 0. Note that it must end with "\ 0, then you have successfully connected to the specified server.