tags:

views:

823

answers:

2

I am building a silverlight app and would like to add p2p capabilities - allowing users to send each other data.

  • Is it available out of the box?
  • Should I wait for silverlight 4.0?
  • Do I need a p2p server?
+2  A: 

I don't think you could make this work in Silverlight with a serverless environment.

You could probably do whatever you're looking to do with a server and a web service, although this technically wouldn't be a peer-to-peer application anymore. You'd have to send your messages to the server, and the server would then send to the appropriate client(s). If you follow this route you might also want to look into WCF RIA Services for Silverlight as it has built-in support for things like authentication.

EDIT -- I don't know if this is an option but it looks like someone has come up with a way to do P2P in Silverlight. However, it requires that you run the app in Windows Live Messenger:

http://www.codeplex.com/SilverlightP2P

Steve Wortham
I don't think WCF RIA Services would help here. P2P in Silverlight would require you to use sockets and to be able to talk to peer sockets you would have to have the client access file modified with the right port and such. Silverlight isn't really meant to be a serverless technology, so for that app I'd go with WPF instead.
Bryant
+3  A: 

The key problem is actually opening the client-side socket to accept connections from another machine, and Silverlight doesn't support this, even in out-of-browser mode, and even in Silverlight 4. If you wanted to do something like this, as the other folks have mentioned, you need a common server that both clients can connect to and which will proxy the messages back and forth between clients. And of course, the fact that Silverlight sockets are limited to ports 4502-4532 also means that you're somewhat limited by firewall policies.

What we've done with our applications (using Silverlight 4) is to try to connect with the new support for Net.TCP (which scales much better), and then if that fails, fallback to the HttpDuplexBinding (which runs over HTTP and hence is more likely to make it through a firewall). We then wrote a WCF service which receives messages from one client and submits them to other subscribing clients. It's not P2P, but it allows for a similar result (apart from all the actual benefits of P2P connections).

If you move to WPF, you give up on the portability of Silverlight, of course, but you get full server socket support, along with the ability to code various NAT traversal strategies like STUN and TURN.

Ken Smith
Nice, I like the idea of using NET.TCP and degrading gracefully.
Marcel Lamothe