Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Resolve Method (PeerName)

PeerNameResolver.Resolve Method (PeerName)

Resolves the specified PeerName in all clouds known to the calling peer.

Namespace:  System.Net.PeerToPeer
Assembly:  System.Net (in System.Net.dll)

public PeerNameRecordCollection Resolve(
	PeerName peerName
)

Parameters

peerName
Type: System.Net.PeerToPeer.PeerName

The PeerName to resolve.

Return Value

Type: System.Net.PeerToPeer.PeerNameRecordCollection
A PeerNameRecordCollection that contains all peer name records (represented as PeerNameRecord objects) associated with the specified peer name. For unsecured peer names, the same PeerName can be registered by different users in the same Cloud, and associated with different endpoints.

ExceptionCondition
ArgumentNullException

The peerName parameter is set to null.

PeerToPeerException

The peer name specified cannot be resolved.

This method associates a peer name to clouds. All clouds are queried for the PeerName. If the peer name cannot be resolved or is null, an PeerToPeerException is thrown.

For unsecured peer names, the same name can be registered (and associated with different endpoints) by different peers within the same cloud.

Calling the PeerNameResolver method is similar to calling the Resolve method for each peer name record in the PeerNameRecordCollection. Note that using the Resolve method on an individual peer name record does not invalidate resolving multiple peer names.

For every Resolve method, there is an equivalent ResolveAsync method. Their parameter lists are identical, except that the ResolveAsync method includes a system token for asynchronous event handling.

If the Cloud parameter is not supplied, the method uses the Available shortcut to fill in cloud parameters.

The ResolveCompleted event will be raised if the resolve operation completes in error or is canceled.

The following code example illustrates how to resolve a PeerName published in any Cloud.

static void Main(string[] args)
{
    try
    {

        if (args.Length != 1)
        {
            Console.WriteLine("Usage: PeerNameResolver.exe <PeerNameToResolve>");
            return;
        }

        // create a resolver object to resolve a Peer Name that was previously published
        PeerNameResolver resolver = new PeerNameResolver();
        // The Peer Name to resolve must be passed as the first  
        // command line argument to the application
        PeerName peerName = new PeerName(args[0]);
        // Resolve the Peer Name  
        // This is a network operation and will block until the resolve completes
        PeerNameRecordCollection results = resolver.Resolve(peerName);

        // Display the data returned by the resolve operation
        Console.WriteLine("Resolve operation complete.\n", peerName);
        Console.WriteLine("Results for PeerName: {0}", peerName);
        Console.WriteLine();

        int count = 1;
        foreach (PeerNameRecord record in results)
        {
            Console.WriteLine("Record #{0} results...", count);

            Console.Write("Comment:");
            if (record.Comment != null)
            {
                Console.Write(record.Comment);
            }
            Console.WriteLine();

            Console.Write("Data:");
            if (record.Data != null)
            {
                // Assumes the data blob associated with the PeerName  
                // is made up of ASCII characters
                Console.Write(System.Text.Encoding.ASCII.GetString(record.Data));
            }
            Console.WriteLine();

            Console.WriteLine("Endpoints:");
            foreach (IPEndPoint endpoint in record.EndPointCollection)
            {
                Console.WriteLine("\t Endpoint:{0}", endpoint);
                Console.WriteLine();
            }

            count++;
        }

        Console.ReadKey();
    }
    catch (Exception e)
    {
        Console.WriteLine("Error occured while attempting to resolve the PeerName: {0}", e.Message);
        Console.WriteLine(e.StackTrace);

        // P2P is not supported on Windows Server 2003 
        if (e.InnerException != null)
        { 
            Console.WriteLine("Inner Exception is {0}", e.InnerException);
        }    
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft