net-mdns icon indicating copy to clipboard operation
net-mdns copied to clipboard

Cannot get the device IP address

Open kingeaglewang opened this issue 4 years ago • 0 comments

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.

kingeaglewang avatar Dec 09 '20 03:12 kingeaglewang