richardschneider / net-mdns

Simple multicast DNS
MIT License
232 stars 81 forks source link

Cannot get the device IP address #101

Open kingeaglewang opened 3 years ago

kingeaglewang commented 3 years ago

In your example code,

        mdns.AnswerReceived += (s, e) =>
        {
               // Is this an answer to a service instance details?
               var servers = e.Message.Answers.OfType<SRVRecord>();
               foreach (var server in servers)
               {
                  Console.WriteLine($"host '{server.Target}' for '{server.Name}'");

                  // Ask for the host IP addresses.
                  mdns.SendQuery(server.Target, type: DnsType.A);
                  mdns.SendQuery(server.Target, type: DnsType.AAAA);
               }

            // Is this an answer to host addresses?
            var addresses = e.Message.Answers.OfType<AddressRecord>();
            foreach (var address in addresses)
            {
                Console.WriteLine($"host '{address.Name}' at {address.Address}");
            }

        };

I cannot get the address most of time, I can only get the server.Name. I need to call sd.QueryServiceInstances(mServiceType); many times, I finally can get address.

Is any thing I need to do? Thanks.