Integrate cross-origin service files in program code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.