Skip to content

Commit

Permalink
[wsmc/Java] Use null wildcard address. Closes GH-30
Browse files Browse the repository at this point in the history
  • Loading branch information
deathcap committed Feb 10, 2016
1 parent a1ebd82 commit 541a9bd
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/main/java/deathcap/wsmc/web/WebThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,7 @@ public void run() {
SocketAddress socketAddress;

if (this.wsAddress == null || this.wsAddress.equals("")) {
try {
// At least on my system, (InetAddress)null and bind(port) (no address) will only bind IPv6 for
// some reason. IPv4 is obviously more or as important. NetUtil.LOCALHOST4 will force IPv4
// localhost (= 127.0.0.1, 0.0.0.0, localhost) but break IPv6 ([::1] and global IPv6 address).
// InetAddress.getLocalHost(), despite the name, will break accessing by localhost (someone will
// return HTTP 200 "Not implemented" [not 501 Not Implemented]), for unknown reasons. But it works
// with the (usually RFC1918) IPv4 network address, so it's the best I know how to do for now.
// TODO: really bind to everything! loopback, ethernet, each IPv4 (and perhaps IPv6), just make it work
// for more failed attempts see https://github.com/deathcap/wsmc/issues/30
socketAddress = new InetSocketAddress(InetAddress.getLocalHost(), this.wsPort);
} catch (UnknownHostException ex) {
System.out.println("Could not find local host: " + ex);
ex.printStackTrace();

socketAddress = new InetSocketAddress((InetAddress) null, this.wsPort);
}
socketAddress = new InetSocketAddress((InetAddress) null, this.wsPort);
} else {
socketAddress = new InetSocketAddress(this.wsAddress, this.wsPort);
}
Expand Down

0 comments on commit 541a9bd

Please sign in to comment.