Question

So I'm running a webapp with an instance of

org.apache.mina.common.IoAcceptor

instantiated as such:

IoAcceptor acceptor = new SocketAcceptor();
SocketAcceptorConfig config = (SocketAcceptorConfig) acceptor.getDefaultConfig();
config.setReuseAddress(true);
config.getFilterChain().addLast("codec", new ProtocolCodecFilter(newFIXProtocolCodecFactory()));
acceptor.bind(new InetSocketAddress(port), clientHandler);

Well that all works swimmingly--we accept connections all day long on a field of tulips while talking to remote clients.

The issue is when trying to disconnect.

So far, I'm attempting a simple,

acceptor.unbindAll();

which appears to work fine in Windows, but when I deploy to my Tomcat server running on linux, the port appears to be listening even after I should theoretically be disconnected. (both netstat and my inability to open sockets to this port confirm)

I believe I'm having the same issue as: http://objectmix.com/apache/717994-unbind-not-working.html

Which of course is an instance of: http://xkcd.com/979/

Was it helpful?

Solution

According to their own test suite, unbind() should work. However, I've found that I need to be a bit more forceful to get it to work reliably on Android. YMMV.

acceptor.setCloseOnDeactivation(true);
for (IoSession ss : acceptor.getManagedSessions().values()) {
  ss.close(true);
}
acceptor.unbind();
acceptor.dispose();

I almost moved on without remembering to tell you what I saw, but the echoes of DenverCoder9 brought me back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top