Silverlight Socket Comments
During my experience with Silverlight 2 beta 1 and the use of sockets I have collected some comments that may help you starting with sockets inside Silverlight:
- The current beta version 1 of Silverlight 2 starts a reverse DNS lookup for the host name you connect to (more details). This will be changed in future versions.
- To connect to a server you have to create an instance of DnsEndPoint class which can be done like this:
- One additional restriction on Silverlight 2 beta 1 is that the port range that a network application is allowed to connect to must be within the range of 4502-4532. These are the only ports allowed for connection from the current beta except the port number the .XAP file is downloaded from which is by default port 80 for http Web applications.
- There is no synchronous connect, send or receive available (I'm very happy about that!).
- IPv4 or IPv6 are both available depending if local computer has support enabled for each.
DnsEndPoint endPoint = new DnsEndPoint( Application.Current.Host.Source.DnsSafeHost, Application.Current.Host.Source.Port);
Site of origin connectivity is intended only as an interim solution in the beta 1 until the full cross-domain model can be put in place for Silverlight 2.
I got a question if it is possible to start a socket listener on the client-side Silverlight application. Well, I cannot find any info that this will be able as I don't see any real use of it. Replacing polling is already very easy by opening a socket to a server and waiting for any response (on event). The next days I will publish my chat example using sockets online.
6 Comments
Comments have been disabled for this content.
Cameron said
Going to start playing around with sockets tonight, this will be very helpful, thanks a lot!
Ilya Goberman said
It looks like it is not possible to connect a socket from a thread that is not "Silverlight thread". What is the background on it? Is there way to make a thread "silverlight compatible"?
Shtong said
I was wondering, what about local "servers" providing specific informations that Silverlight should not be allowed to access? I have in mind the WiiFlash application that allows the use of a Wii console controller (the famous Wiimote)in a flash application, by installing a local server that will get the Wiimote input and send it to the Flash application through a local TCP connection. I didn't makev any testing with Silverlight about this so far but what I understand from your Socket post series is that it's impossible for Silverlight to connect to a local server. I understand that could be a serious security issue, but it is possible to allow a specified flash application to connect to local resources. It would be nice if we could similary change the security restrictions for a silverlight application.
Tim Lloyd said
A use that I can think of for a socket listener (and I would use SilverLight if it could support it) is that of implementing a pattern where a stream needs to be pre-processed before passing it onto a MediaElement. A good candidate for this is a media stream that contains both meta-data and mp3. The meta-data needs to be filtered out before passing on the mp3 content to the MediaElement. This would be possible if a listener was supported, as the MediaElement would have the listener address as its source, and the listener implementation could do the pre-processing. Am I correct in thinking that there is no way to currently achieve this behavior? Thanks, Tim.
Tim Lloyd said
Another use for listeners.. For example I want to stream mp3s from an http source that requires specific http headers (e.g. from a RESTful service such as Amazon S3 storage). With a listener I can proxy MediaElement requests and then subsequently use a raw socket to form a request with the required headers. Custom proxy functionality (i.e. client socket server capability) make listener sockets a useful proposition. Thanks, Tim.
justin said
I think a silverlight client side socket listening functionality is a revolution part of browser. This will enable p2p applications by using silverlight. I am trying to find such a plugin ...