15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1352 ❘ ChaPTer 45 peer-tO-peer netwOrkinG<br />

}<br />

PeerList.Items.Clear();<br />

RefreshButton.IsEnabled = false;<br />

// Resolve unsecured peers asynchronously<br />

resolver.ResolveAsync(new PeerName("0.P2P Sample"), 1);<br />

The remainder of the code is responsible for displaying <strong>and</strong> communicating with peers, <strong>and</strong> you can explore<br />

it at your leisure.<br />

Exposing WCF endpoints through P2P clouds is a great way of locating services within an enterprise, as<br />

well as being an excellent way to communicate between peers, as in this example.<br />

system.net.PeerToPeer.Collaboration<br />

The classes in the System.Net.PeerToPeer.Collaboration namespace provide a framework you can use<br />

to create applications that use the People Near Me service <strong>and</strong> the P2P collaboration API. As mentioned<br />

earlier, at the time of writing this is only possible if you are using Windows Vista or Windows 7.<br />

You can use the classes in this namespace to interact with peers <strong>and</strong> applications in a number of ways, including<br />

➤<br />

➤<br />

➤<br />

Signing in <strong>and</strong> signing out<br />

Discovering peers<br />

Managing contacts <strong>and</strong> detecting peer presence<br />

You can also use the classes in this namespace to invite other users to join an application, <strong>and</strong> to exchange<br />

data between users <strong>and</strong> applications. However, to do this you need to create your own PNM-capable applications,<br />

which is beyond the scope of this chapter.<br />

In the following sections, all the types referred to come from the System.Net.PeerToPeer.Collaboration<br />

namespace unless otherwise specified.<br />

signing in <strong>and</strong> signing out<br />

One of the most important classes in the System.Net.PeerToPeer.Collaboration namespace is the<br />

PeerCollaboration class. This is a static class that exposes numerous static methods that you can use<br />

for various purposes, as you will see in this <strong>and</strong> subsequent sections. You can use two of the methods<br />

it exposes, SignIn() <strong>and</strong> SignOut(), to (unsurprisingly) sign in <strong>and</strong> sign out of the People Near Me<br />

service. Both of these methods take a single parameter of type PeerScope, which can be one of the<br />

following values:<br />

➤<br />

➤<br />

➤<br />

➤<br />

PeerScope.None — If you use this value, SignIn() <strong>and</strong> SignOut() will have no effect.<br />

PeerScope.NearMe — This will sign you in to or out of the link local clouds.<br />

PeerScope.Internet — This will sign you in to or out of the global cloud (which may be necessary<br />

to connect to a contact who is not currently on your local subnet).<br />

PeerScope.All — This will sign you in to or out of all available clouds.<br />

If necessary, calling SignIn() will cause the People Near Me configuration dialog to be displayed.<br />

When a peer is signed in you can use the PeerCollaboration.LocalPresenceInfo property to a value<br />

of type PeerPresenceInfo. This enables st<strong>and</strong>ard IM functionality, such as setting your status to away.<br />

You can set the PeerPresenceInfo.DescriptiveText property to a Unicode string of up to 255 characters,<br />

<strong>and</strong> the PeerPresenceInfo.PresenceStatus property to a value from the PeerPresenceStatus<br />

enumeration. The values that you can use for this enumeration are as follows:<br />

➤<br />

➤<br />

PeerPresenceStatus.Away — The peer is away.<br />

PeerPresenceStatus.BeRightBack — The peer is away, but will be back soon.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!