Hi Aneel, try adding these two lines:
SocketSessionConfig config = (SocketSessionConfig) acceptor.getSessionConfig (); config.setReuseAddress(true); This will set reuseAddress true for all accepted sockets. Maarten On 5/25/07, Aneel Nazareth <[EMAIL PROTECTED]> wrote:
I've been having a problem that I thought I knew how to resolve: If I stop my Mina (1.1.0) server when it has clients connected, and then try to immediately restart it, I get a BindException complaining that the address is already in use. When this happens, netstat shows some connections in TIME_WAIT, but nothing listening on the port. I thought that setReuseAddress would fix this problem, but it doesn't seem to. Am I missing something? Here's the piece of my code with the bind in question: // Prepare the configuration SocketAcceptorConfig config = new SocketAcceptorConfig(); config.setReuseAddress( true ); // Bind the the User Handler to its address userAcceptor = new SocketAcceptor(); System.out.println( "Running " + userHandler + " on " + this.userAddress ); System.out.println("Reuse? " + config.isReuseAddress()); userAcceptor.bind( this.userAddress.getSocketAddress(), userHandler, config ); On stdout I see: Running [EMAIL PROTECTED] on doomsong.shockwave.com:20000 Reuse? true But I get: java.net.BindException: Address already in use at sun.nio.ch.Net.bind(Native Method) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java :59) at org.apache.mina.transport.socket.nio.SocketAcceptor.registerNew( SocketAcceptor.java:400) at org.apache.mina.transport.socket.nio.SocketAcceptor.access$900( SocketAcceptor.java:55) at org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run( SocketAcceptor.java:235) at org.apache.mina.util.NamePreservingRunnable.run( NamePreservingRunnable.java:43) at java.lang.Thread.run(Thread.java:595)