After getting the basic framework for the server going and writing a small chat application, I was able to verify that the server was working correctly by utilizing the PuTTY terminal software. My next step was to write a basic client in Silverlight 2 to replace PuTTY.
Getting Started seemed easy enough. Just visit the Getting Started section on http://silverlight.net
Here’s a quick rundown of the required steps:
- Make sure Visual Studio 2008 is updated to SP1
- Install the Silverlight Tools for Visual Studio 2008 SP1
- Download the Silverlight Toolkit
Easy enough. Well, not exactly. It took a bit to download and update Visual Studio. Everything else was pretty quick.
Moving on, I started by doing a bit of research on the web with utilizing sockets in Silverlight 2. It’s important to remember that Silverlight 2 doesn’t contain the full .Net framework and that for security reasons, many API’s are limited or not available.
Sockets proved to be no different. While the API’s are basically the same, I couldn’t get my sample application to connect to my localhost. I kept getting an accessed denied error. After spending many more hours on the web doing some research, it turns out that there are a few restrictions and a special service one must be running to get this to work correctly.
I’ll save you the gory details. Those can be found on MSDN
http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx
Quick summary:
A service must be listening on port 943 that can serve up a policy file similar to the following:
<?xml version="1.0" encoding ="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from>
<domain uri="*" />
</allow-from>
<grant-to>
<socket-resource port="4529-4534" protocol="tcp" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
The Silverlight 2 application is only allowed to open a connection back to the same server that launched the application. It will then get the above policy file and use the rules to determine if it has permissions to talk to the server.
Once that hurdle was completed, the application started working like a charm.