• Important change to Sockets in Silverlight 2


    An important note for those using Sockets in Silverlight 2.  In beta 1, Sockets were limited to site-of-origin (meaning you could only connect back to the same host that served up the Silverlight application).  This has changed in beta 2 to allow your Silverlight application to connect to any server exposing some Socket connections.

    One important note, however, is that a policy implementation has been added.  This policy implementation affects not only cross-domain Socket calls, but site-of-origin ones as well.  So if you are using Sockets, you must have a policy implementation in place.

    The policy implementation is done via a similar file mechanism as HTTP-based cross-domain requests.  The policy file looks similar and here is a basic example:

    <?xml version="1.0" encoding ="utf-8"?>
    <access-policy>
      <cross-domain-access>
        <policy>
          <allow-from>
            <domain uri="file:///" />
          </allow-from>
          <grant-to>
            <socket-resource port="4502-4506" protocol="tcp" />
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>
    Notice how you can restrict the ports here (note: Sockets in general in Silverlight are limited to ports 4502-4534).

    This policy information must be made available on a TCP port request on port 943.  Any Socket request will first look for that policy information to respond on this port 934 request.  If successful, the remaining communication will be allowed.  If not, the communication will fail.

    UPDATE: I accidentally typed "934" originally as the port -- it is 943.

    There is no code change you need to have in your current Socket implementation other than implementing a Socket policy server to respond to the policy request.  I’ll be covering the basics of sockets on a video over on the Silverlight community site which will demonstrate and provide code on doing this implementation.  Stay tuned for that one.

    Hope this helps.


    This work is licensed under a Creative Commons Attribution By license.

    Friday, June 06, 2008 9:06 PM

    PostTypeIcon

Comments.

  • Gravatar
    # re: Important change to Sockets in Silverlight 2


    Nice! Is the same functionality being implemented for standard HTTP requests, or are they still same server only at the moment?

    6/7/2008 2:29 AM
  • Kellen said:
    Gravatar
    # re: Important change to Sockets in Silverlight 2


    In future releases of Silverlight will supported sockets be expanded? Will the need of this policy file be removed? I am creating a silverlight client for an application I am not in control of, so far in beta I have had to create a relay server that accepts communication on ports 4502-4534 and sends all information to the real destination. This will not work in production.

    I think Silverlight needs to have an option to open up ports with a prompt akin to the local storage expansion, this will allow the creation of a wide variety of clients and will not expose a security risk.

    6/7/2008 1:05 PM
  • timheuer said:
    Gravatar
    # re: Important change to Sockets in Silverlight 2


    @m.david: There already exists a similar policy file for cross-domain communication via HTTP -- been there since Beta 1. We also support a limited set of Adobe's crossdomain.xml structure.

    @Kellen: the policy structure will remain. your relay server doesn't have to accept on the wide range of ports you can specify a specific one to use for communication. Additionally, the prompting for 'open port' really wouldn't help since the network owner has to enable communication through firewalls, etc. Sockets may not be ideal in every situation, but where they can be used for specific scenarios (i.e., multi player gaming, etc.) it is a great choice.

    6/7/2008 1:21 PM
  • Mike said:
    Gravatar
    # re: Important change to Sockets in Silverlight 2


    There's a video up at;

    http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/06/07/10493.aspx

    which does the very basics of getting a socket client/server up and running with a policy server.

    Mike.

    6/9/2008 2:19 AM
  • Gravatar
    # re: Important change to Sockets in Silverlight 2


    Thanks for the port number Tim,

    I've published a substantial example based around a ticking stock list that demonstrates the Socket support in Silverlight 2 Beta 2 including handling the new policy requirements in the same server on a separate thread.

    http://petermcg.wordpress.com/2008/06/10/samples-updated-to-beta2/

    Peter

    6/10/2008 4:28 AM
  • Gravatar
    # re: Important change to Sockets in Silverlight 2


    Do we need a policy server if we are targeting the local machine via 127.0.0.1?

    If so, can I set up local IIS on 127.0.0.1:943 and where do I put the file?

    Can I use localhost for:

    <allow-from>
    <domain uri="localhost" />
    </allow-from>

    I started out looking for a simple way to communicate with other programs on the local computer and this is turning into an 'adventure'

    -Jay

    7/6/2008 12:18 PM
  • timheuer said:
    Gravatar
    # re: Important change to Sockets in Silverlight 2


    @Jay: yes, a policy server is required in all socket communication now. Take a look at http://silverlight.net/blogs/msnow/archive/2008/06/26/full-implementation-of-a-silverlight-policy-server.aspx

    7/6/2008 2:24 PM

Your Reply.

  Comment Form  

Fields denoted with a "*" are required.

*Your name:
Subject:
Your blog:
Your email:  (will not be displayed)
*Your message:

 
Please add 5 and 7 and type the answer here: