Closed
Description
I'm using huzzah esp8266 board with esp8266 arduino version 2.3.0
I made a http endpoint to test mdns service query and here is the piece of code:
`
void queryMDNS() {
String s;
Serial.println("Sending mDNS query");
Serial.print(server.argName(0));
Serial.print(":");
Serial.println(server.arg(0));
String service = server.arg(0);
s = "<!DOCTYPE HTML>\r\n<html><body>node(WiFi) ";
int n = MDNS.queryService(service, "tcp"); // Send out query for esp tcp services
Serial.println("mDNS query done");
if (n == 0) {
Serial.println("no services found");
s += "<p>No service found</p></body></html>";
} else {
Serial.print(n);
Serial.println(" service(s) found");
s += "<p>Service found</p>";
for (int i = 0; i < n; ++i) {
// Print details for each service found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(MDNS.hostname(i));
s += "<p>";
s += i + 1;
s += " ";
s += MDNS.hostname(i);
Serial.print(" (");
Serial.print(MDNS.IP(i));
Serial.print(":");
Serial.print(MDNS.port(i));
Serial.println(")");
s += " (";
s += MDNS.IP(i);
s += ":";
s += MDNS.port(i);
s += ")</p>";
}
}
server.send(200, "text/html", s);
}
`
To invoke this query I access to the url like follows:
http://ESP_IP_ADDR/mdns?service=SERVICENAME
and this query returns hostname and port.
But the problem is when the query fails.
Even the query failed, MDNS.queryService and MDNS.hostname() , IP(), port()...
they still return previously discovered servie host information.
And after the query gets the right response with service information, those hostname(), IP(), port()... are refreshed with proper answer right away.