Trustin,

Thanks very much for your reply.
Removing the local address in the "IoConnector.connect" method, worked OK
for up to about 1000 client connections :)

But with more than 1000 connections, I still get the
"java.net.BindException: Address already in use..." exception as below, on
the line:     "clientSessions[ j ] = future.getSession();"
Could this be a timing issue - I have tried putting a Thread.Sleep() after
the "future.join();", to establish the connection, with only limited
success.
I have also tried checking the values of "future.isReady()" and
"future.isConnected()", which come back as false as more and more
connections are made as the loop progresses.


Code:
IoSession[] clientSessions = new IoSession[ 2000 ];
InetSocketAddress serverSocketaddress = new InetSocketAddress( "localhost",
port );
ClientSessionHandler clientHandler = new ClientSessionHandler();
for( int j = 0; j < 2000; j++ ) {
    IoConnector connector = new SocketConnector();
    ConnectFuture future = connector.connect( serverSocketAddress,
clientHandler );
    future.join();
    clientSessions[ j ] = future.getSession();
}

Exception Stack trace:
.....
39969 [AnonymousIoService-5-612] INFO org.server.ServerSessionHandler -
[/127.0.0.1:3978] OPENED
40000 [AnonymousIoService-5-609] INFO org.server.ServerSessionHandler -
[/127.0.0.1:3981] OPENED
40031 [AnonymousIoService-5-612] INFO org..server.ServerSessionHandler -
[/127.0.0.1:3984] OPENED
40063 [AnonymousIoService-5-609] INFO org..server.ServerSessionHandler -
[/127.0.0.1:3989] OPENED
testTCPConnectorMultipleClients(): Failed to connect.
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:242)
        at
org.game.poker.server.ConnectionTest.testTCPConnectorMessages(ConnectionTest
.java:103)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
Caused by: java.net.BindException: Address already in use: no further
information
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at
sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:525)
        at
org.apache.mina.transport.socket.nio.support.SocketConnectorDelegate.process
Sessions(SocketConnectorDelegate.java:229)
        at
org.apache.mina.transport.socket.nio.support.SocketConnectorDelegate.access$
800(SocketConnectorDelegate.java:49)
        at
org.apache.mina.transport.socket.nio.support.SocketConnectorDelegate$Worker.
run(SocketConnectorDelegate.java:321)
....



Regards,
Matt

  -----Original Message-----
  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Trustin Lee
  Sent: 20 May 2006 14:12
  To: Matt Keane
  Subject: Re: FW: Connection Exception


  On 5/20/06, Matt Keane <[EMAIL PROTECTED]> wrote:
    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()).setReuseAddres
s(true);

    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?

  Is there any reason that you specify the local address of the connection?
I think your problem will disappear if you don't specify the local address
parameter.

  HTH,
  Trustin
  --
  what we call human nature is actually human habit
  --
  http://gleamynode.net/
  --
  PGP key fingerprints:
  * E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
  * B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Reply via email to