diff --git a/src/dorkbox/network/Server.java b/src/dorkbox/network/Server.java index 66627b11..3e9ec224 100644 --- a/src/dorkbox/network/Server.java +++ b/src/dorkbox/network/Server.java @@ -85,6 +85,7 @@ class Server extends EndPointServer { private final int udtPort; private final String localChannelName; + private final String hostName; /** * Starts a LOCAL only server, with the default serialization scheme. @@ -119,6 +120,14 @@ class Server extends EndPointServer { localChannelName = options.localChannelName; + if (options.host == null) { + hostName = "0.0.0.0"; + } + else { + hostName = options.host; + } + + if (localChannelName != null) { localBootstrap = new ServerBootstrap(); } @@ -234,8 +243,9 @@ class Server extends EndPointServer { registrationWrapper, serializationManager)); + // have to check options.host for null. we don't bind to 0.0.0.0, we bind to "null" to get the "any" address! if (options.host != null) { - tcpBootstrap.localAddress(options.host, tcpPort); + tcpBootstrap.localAddress(hostName, tcpPort); } else { tcpBootstrap.localAddress(tcpPort); @@ -371,13 +381,17 @@ class Server extends EndPointServer { future = tcpBootstrap.bind(); future.await(); } catch (Exception e) { - String errorMessage = stopWithErrorMessage(logger2, "Could not bind to TCP port " + tcpPort + " on the server.", e); + String errorMessage = stopWithErrorMessage(logger2, + "Could not bind to address " + hostName + " TCP port " + tcpPort + + " on the server.", + e); throw new IllegalArgumentException(errorMessage); } if (!future.isSuccess()) { String errorMessage = stopWithErrorMessage(logger2, - "Could not bind to TCP port " + tcpPort + " on the server.", + "Could not bind to address " + hostName + " TCP port " + tcpPort + + " on the server.", future.cause()); throw new IllegalArgumentException(errorMessage); } @@ -393,13 +407,16 @@ class Server extends EndPointServer { future = udpBootstrap.bind(); future.await(); } catch (Exception e) { - String errorMessage = stopWithErrorMessage(logger2, "Could not bind to UDP port " + udpPort + " on the server.", e); + String errorMessage = stopWithErrorMessage(logger2, "Could not bind to address " + hostName + " UDP port " + + udpPort + " on the server.", + e); throw new IllegalArgumentException(errorMessage); } if (!future.isSuccess()) { String errorMessage = stopWithErrorMessage(logger2, - "Could not bind to UDP port " + udpPort + " on the server.", + "Could not bind to address " + hostName + " UDP port " + udpPort + + " on the server.", future.cause()); throw new IllegalArgumentException(errorMessage); } @@ -415,13 +432,15 @@ class Server extends EndPointServer { future = udtBootstrap.bind(); future.await(); } catch (Exception e) { - String errorMessage = stopWithErrorMessage(logger2, "Could not bind to UDT port " + udtPort + " on the server.", e); + String errorMessage = stopWithErrorMessage(logger2, "Could not bind to address " + hostName + " UDT port " + + udtPort + " on the server.", e); throw new IllegalArgumentException(errorMessage); } if (!future.isSuccess()) { String errorMessage = stopWithErrorMessage(logger2, - "Could not bind to UDT port " + udtPort + " on the server.", + "Could not bind to address " + hostName + " UDT port " + udtPort + + " on the server.", future.cause()); throw new IllegalArgumentException(errorMessage); }