I recently used some small games, including socket, flash on the client, and C # on the server #. The socket used for communication is good locally, but when it is put on the server, the error "the software in your host has terminated an established connection" occurs. I searched a lot, network Problems, firewalls, and so on are all useless. Finally, the spam has not been resolved. No way. I finally saw <policy-file-Request/> during debugging. Isn't this related to permissions? So I found some materials and found that Adobe is really a pain point. I listed the key points online. (Web site: http://hi.baidu.com/dobodo/blog/item/b1614aea02efe8dfd439c967.html) is as follows:
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. In the entire SWF
During running, no matter how many requests you request, as long as the domain is the same, Flash Player only verifies once. There are two key points:
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 that the verified socket sends "<policy-file-Request/> \ 0" requests 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.
In Java, the method I handle is to independently start a service with port 843 to listen for authorization requests. In this way, the client responds quickly. The code snippet is as follows:
String xml = "<? XML version = \ "1.0 \"?> <Cross-domain-Policy> <site-control permitted-Cross-Domain-policies = \ "all \"/> <allow-access-from domain = \ "* \" -ports = \ "* \"/> </Cross-Domain-Policy> \ 0 ";
Socket socket = serversocket. Accept ();
Bufferedreader BR = new bufferedreader (New inputstreamreader (socket
. Getinputstream (), "UTF-8 "));
Printwriter PW = new printwriter (socket. getoutputstream ());
Char [] by = new char [22];
BR. Read (by, 0, 22 );
String S = new string ();
System. Out. println ("s =" + S );
If (S. Equals ("<policy-file-Request/> ")){
System. Out. println ("receive policy-file-request ");
PW. Print (XML );
PW. Flush ();
BR. Close ();
PW. Close ();
Socket. Close ();
}
In addition, pay attention to the "\ 0" after the XML string, because Flash Player uses it as the separator. If you do not add it, the client may wait until the socket is verified. In addition, the socket for receiving authorization must be disconnected.