Hi

The 'Address already in use' problem outlined below seems to be a particular
quirk of the TCP protocol, and not MINA specific, whereby, even though the
Server's socket connection has been closed, "the server goes into a
TIME_WAIT state, just to be really really sure that all the data has gone
through.". For more info on TIME_WAIT, see:
http://www.developerweb.net/forum/showthread.php?t=2941

I have tried adding the following line in the Server code, but I still get
the same Exception as below:
((SocketAcceptorConfig)socketAcceptor.getDefaultConfig()).setReuseAddress(tr
ue);

The only solution I have found, is to wait for 5-10 minutes and try running
the connection test again, and they pass Ok.


Any ideas as to how to we could handle this?


Regards,
Matt


-----Original Message-----
From: Matt Keane [mailto:[EMAIL PROTECTED]
Sent: 18 May 2006 21:46
To: [email protected]
Cc: [EMAIL PROTECTED]
Subject: Connection Exception


Hi

I've created a simple test harness for a TCP Client / Server application.
If run the ConnectionTest() first time, its Ok. Then, I run it again
multiple times, a socket already bound exception occurs (I think at
"future.getSession()" )
For some reason, the connector seems to still think its bound to a port.
See code and exception below
I'm using MINA 0.9.3.

public class ConnectionTest extends TestCase {
....
protected void setUp() throws Exception {
        Server.start(); // does initialisation and socketAcceptor.bind(
socketAddress, sessionHandler, socketAcceptorConfig ) ....
}

protected void tearDown() throws Exception {
        Server.stop(); // does socketAcceptor.unbindAll()
}

public void testTCPMultipleClients() throws Exception {
        int port = 1;
        InetSocketAddress address = new InetSocketAddress( "localhost",
port );
        ClientSessionHandler clientHandler = new ClientSessionHandler();
        int clientPort = 1;
        final int MAX_CLIENT_SESSIONS = 100;
        IoSession[] clientSessions = new IoSession[ MAX_CLIENT_SESSIONS ];
        try {
            System.out.println("* Test Connections" );
            for( int j = 0; j < clientSessions.length; j++ ) {
                clientPort = AvailablePortFinder.getNextAvailable(
clientPort + 1 );
                InetSocketAddress localAddress = new InetSocketAddress(
clientPort );
                IoConnector connector = new SocketConnector();
                ConnectFuture future = connector.connect( address,
localAddress, clientHandler );
                future.join();
                clientSessions[ j ] = future.getSession();
            }
        } catch( Exception e ) {
            e.printStackTrace();
        }
 }
}

Exception StackTrace as follows:
java.io.IOException: Failed to get the session.
        at
org.apache.mina.common.ConnectFuture.getSession(ConnectFuture.java:73)
        at
org.game.poker.server.ConnectionTest.testTCPConnectorMultipleClients(Connect
ionTest.java:202)
        at
org.game.poker.server.ConnectionTest.testTCPConnectorMessages(ConnectionTest
.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585) ....
Caused by: java.net.BindException: Address already in use: no further
information


Any ideas?

Many Thanks,
Matt





Reply via email to