当前位置: 首页>>代码示例>>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;未经允许,请勿转载。