I'm using mina 2.0.0-M6 to connect to a client on localhost. Up to now I've
been creating InetSocketAddress without specifying the hostname, like this:
protected static void connect(int port) {
// create address with implicit hostname
InetSocketAddress addr= new InetSocketAddress(port);
logger.debug("trying to connect to {}", addr);
NioSocketConnector connector= new NioSocketConnector();
connector.setHandler(new IoHandlerAdapter());
ConnectFuture cf= connector.connect(addr);
cf.awaitUninterruptibly();
logger.debug("connected to {}", addr);
IoSession session= cf.getSession();
session.close(true);
}
Most of the time this works fine. However, on some machines this fails-- it
will throw a "Connection Refused" ConnectException, even though the server port
is open.
I discovered that in this case I must create InetSocketAddress by explicitly
specifying 'localhost' for the hostname or it won't work. e.g.,
InetSocketAddress addr= new InetSocketAddress("localhost", port);
I have two Ubuntu hardy machines with very similar configurations, one in which
the implicit hostname works and one in which you must specify 'localhost'.
What is going on here? What is supposed to happen when you leave the hostname
out of InetSocketAddress?
Thanks,
aaron