Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Help required in finding the ipaddress of the service found #28

Closed
maheshgupta opened this issue Sep 29, 2017 · 1 comment
Closed

Help required in finding the ipaddress of the service found #28

maheshgupta opened this issue Sep 29, 2017 · 1 comment

Comments

@maheshgupta
Copy link

I have successfully found using the browse method in DNSSD class and now I'm trying to find the ipaddress of the found service using queryRecord. Unforutantely I'm not able to get the trigger to the QueryListener that is passed to the queryRecord call. I believe that Im doing something wrong, can you please help me what is the mistake in this code.


try {
            this.browseService = dnssd.browse(SERVICE_TYPE, object : BrowseListener {

                override fun serviceFound(browser: DNSSDService, flags: Int, ifIndex: Int,
                                          serviceName: String, regType: String, domain: String) {
                    LoggingUtil.log("Found in Service " + serviceName + " Domain : " + domain)

                    dnssd.queryRecord(flags, ifIndex, serviceName, 1, 1, object : QueryListener {
                        override fun queryAnswered(query: DNSSDService?, flags: Int, ifIndex: Int, fullName: String?, rrtype: Int, rrclass: Int, rdata: InetAddress?, ttl: Int) {

                            LoggingUtil.log("Found the answer for the Query : " + rdata?.hostName + " - " + rdata?.hostAddress + " _ Address : " + String(rdata?.address!!))
                        }

                        override fun operationFailed(service: DNSSDService?, errorCode: Int) {
                            LoggingUtil.log("Unable to find the address : " + errorCode)
                        }

                    })
                }

                override fun serviceLost(browser: DNSSDService, flags: Int, ifIndex: Int,
                                         serviceName: String, regType: String, domain: String) {
                    LoggingUtil.log("Lost " + serviceName)
                }

                override fun operationFailed(service: DNSSDService, errorCode: Int) {
                    LoggingUtil.log("error: " + errorCode)
                }
            })
        } catch (e: DNSSDException) {
            LoggingUtil.log("error : " + e.message)
        }
@andriydruk
Copy link
Owner

Hi, @maheshgupta
You should do Resolve first, than QueryRecords
See my example

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants