Google
 
Web unafbapune.blogspot.com

Sunday, November 30, 2008

 

Local vs Any address in Cajo

Looking into the cajo source code, I see the default server side host address used by cajo is the local host address. For example,
host = InetAddress.getLocalHost().getHostAddress();
This seems to work in most cases/platforms, except it breaks with the new Mac that I have. How does it break ? Well the server side binding works with the default (local) address, but the client would fail to connect to 127.0.0.1 or localhost. To make the client connect, I needed to figure out the specific local address (like 192.168.0.3) used for the server side binding, and explicitly specify that for the client.

When I tried to see if this was also the case outside cajo using the plain old ServerSocket(int), surprisingly it worked regardless of whether I specified locahost, 127.0.0.1, or 192.168.0.3.

Digging more into the JDK source code, ServerSocket uses an "any address" rather than a "local address" as the default:
InetAddress.anyLocalAddress();
Sadly, this static method is package private.

Anyhow, since the "any address" seems to work more so than the "local address", it would be nice if cajo can change the default server side address to the "any address", which would make cajo "just work" across more platforms.

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?