當前位置: 首頁>>代碼示例>>C#>>正文


C# PeerNameResolver.Resolve方法代碼示例

本文整理匯總了C#中System.Net.PeerToPeer.PeerNameResolver.Resolve方法的典型用法代碼示例。如果您正苦於以下問題:C# PeerNameResolver.Resolve方法的具體用法?C# PeerNameResolver.Resolve怎麽用?C# PeerNameResolver.Resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了PeerNameResolver.Resolve方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

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 occurred 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);
        }    
    }
}
開發者ID:.NET開發者,項目名稱:System.Net.PeerToPeer,代碼行數:70,代碼來源:PeerNameResolver.Resolve


注:本文中的System.Net.PeerToPeer.PeerNameResolver.Resolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。