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