Skip to content

Commit

Permalink
Fixed /discovery/list failing with multiple clients on the network (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
devgianlu committed May 11, 2021
1 parent c9f9f53 commit 2745b50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
*/
public final class DiscoveryHandler implements HttpHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(DiscoveryHandler.class);
private final Zeroconf zeroconf;
private final Zeroconf.DiscoveredServices discoverer;

public DiscoveryHandler() {
zeroconf = new Zeroconf()
Zeroconf zeroconf = new Zeroconf()
.setUseIpv4(true)
.setUseIpv6(false);

Expand All @@ -49,6 +49,8 @@ public DiscoveryHandler() {
} catch (IOException ex) {
LOGGER.error("Failed adding network interfaces for Zeroconf.", ex);
}

discoverer = zeroconf.discover(ZeroconfServer.SERVICE, "tcp", ".local");
}

@Override
Expand All @@ -69,7 +71,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
switch (action) {
case "list":
JsonArray array = new JsonArray();
for (DiscoveredService service : zeroconf.discover(ZeroconfServer.SERVICE, "tcp", ".local")) {
for (DiscoveredService service : discoverer.getServices()) {
JsonObject obj = new JsonObject();
obj.addProperty("name", service.name);
obj.addProperty("target", service.target);
Expand Down
2 changes: 1 addition & 1 deletion lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<dependency>
<groupId>xyz.gianlu.zeroconf</groupId>
<artifactId>zeroconf</artifactId>
<version>1.2.2</version>
<version>1.3.0</version>
</dependency>

<!-- HTTP -->
Expand Down

0 comments on commit 2745b50

Please sign in to comment.