Skip to content

Commit 3516d46

Browse files
committed
Catch binding issue
1 parent c8e40b4 commit 3516d46

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/core/ZeroconfServer.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,21 @@ private ZeroconfServer(Session.Inner inner, Configuration conf) throws IOExcepti
110110
txt.put("CPath", "/");
111111
txt.put("VERSION", "1.0");
112112

113+
boolean atLeastOne = false;
113114
instances = new JmDNS[bound.length];
114115
for (int i = 0; i < instances.length; i++) {
115-
instances[i] = JmDNS.create(bound[i], bound[i].getHostName());
116-
ServiceInfo serviceInfo = ServiceInfo.create("_spotify-connect._tcp.local.", "librespot-java-" + i, port, 0, 0, txt);
117-
instances[i].registerService(serviceInfo);
116+
try {
117+
instances[i] = JmDNS.create(bound[i], bound[i].getHostName());
118+
ServiceInfo serviceInfo = ServiceInfo.create("_spotify-connect._tcp.local.", "librespot-java-" + i, port, 0, 0, txt);
119+
instances[i].registerService(serviceInfo);
120+
atLeastOne = true;
121+
} catch (SocketException ex) {
122+
LOGGER.warn("Failed creating socket for " + bound[i]);
123+
}
118124
}
119125

120-
LOGGER.info("SpotifyConnect service registered successfully!");
126+
if (atLeastOne) LOGGER.info("SpotifyConnect service registered successfully!");
127+
else throw new IllegalStateException("Could not register the service anywhere!");
121128
}
122129

123130
@NotNull

0 commit comments

Comments
 (0)