mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aneel Nazareth <anazar...@atom.com>
Subject Address already in use?
Date Fri, 25 May 2007 18:43:03 GMT
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 com.shockwave.banyan.data.DataHandler@1fecaeb 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)

Mime
View raw message