Because Silverlight cross-origin files are frequently used in distributed application development, some simple applications do not need to allow users to dynamically configure cross-origin XML files after the program is released, in this way, it is unnecessary to add an XML cross-domain file in the program directory and the complexity of publishing is increased, therefore, the following method is used to directly integrate cross-domain files into the code in the program.
When I started the cross-origin service, I also integrated the definition of cross-origin files into the code. You can also use custom program functions to dynamically generate dynamic cross-domain files. In this way, users can configure cross-origin rules. The clientaccesspolicy. xml file is no longer required. Haha ..
The following code is used to start the cross-origin service:
1: // book? Text? Source 'chuang? Address: http://funsl.com
2: internal void StartupPolicyServer(int maxOnlines)
3: {
4: _policyBuffer = new byte[371];
5: Stream str = new MemoryStream(System.Text.ASCIIEncoding.Default.GetBytes(
6: @"<?xml version=""1.0"" encoding =""utf-8""?>
7: <access-policy>
8: <cross-domain-access>
9: <policy>
10: <allow-from>
11: <domain uri=""*"" />
12: </allow-from>
13: <grant-to>
14: <socket-resource port=""4502-4534"" protocol=""tcp"" />
15: </grant-to>
16: </policy>
17: </cross-domain-access>
18: </access-policy>"));
19: // book? Text? Source 'chuang? Address: http://funsl.com
20: str.Read(_policyBuffer, 0, _policyBuffer.Length);
21:
22: _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
23: _listener.Bind(new IPEndPoint(IPAddress.Any, 943));
24: _listener.Listen(maxOnlines);
25:
26: _listener.BeginAccept(new AsyncCallback(OnClientConnect), null);
27: }
28:
Run the following code:
1: // book? Text? Original-chuang' location? Address: http://funsl.com
2: jacSocket.crossDomain cd = new jacSocket.crossDomain();
3: cd.StartupPolicyServer(200);
4:
The startuppolicyserver () parameter indicates the maximum number of clients connected to the Cross-origin service. Set this parameter according to your actual situation.