Peer to Peer Series Part 3: Resolving Names Synchronously with the PNRP API
- Posted: Sep 17, 2009 at 6:41 PM
- 10,576 Views
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- WMV (WMV Video)
- MP3 (Audio only)
- MP4 (iPod, Zune HD)
- Mid Quality WMV (Lo-band, Mobile)
In Part 3 of the Peer to Peer Series, I add another Command Prompt application to the demo solution and use the PNRP API to resolve a Peer Name using C#. As with registering a Peer Name, resolving Peer Names is straightforward:
PeerNameResolver resolver = new PeerNameResolver();
try
{
records = resolver.Resolve(new PeerName(classifier, PeerNameType.Unsecured));
if (records.Count > 0)
{
foreach (var record in records)
{
Console.WriteLine("***Peer: {0},record.PeerName.ToString());
Console.Writeline("***Host Name: {0}, record.PeerName.PeerHostName);
Console.Writeline("***Comment: {0}", record.Comment);
foreach (var endpoint in record.EndPointCollection)
Console.WriteLine("\tEndpoint: {0}, Port: {1}", endpoint.Address.ToString(), endpoint.Port);
Console.WriteLine();
}
}
}
catch (PeerToPeerException ex)
{
//Other standard execptions can also be caught
Console.WriteLine("PeerToPeer Excpetion: {0)", ex.Message);
}
One of the interesting things about resolving a Peer Name is that the resulting PeerNameRecords include the endpoint information for each of the Peer Names found. This means you can establish direct connections with those peers if necessary. I will show how to do just that in an upcoming screencast. Of course, that assumes we don’t have any firewalls or other types of security blockades preventing direct communication.
The example in this installment is done synchronously. In the next screencast, I will show you how you can do the same operation asynchronously. This is useful because the Resolve method can take quite a while to return so your program’s execution is blocked while waiting for the method to complete. This is especially bad in the case of GUI applications since the app will become non-responsive while waiting for Resolve to finish.
Other documentation for PNRP:
Download the Demo Code
Comments Closed
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.