Please refer to http://www.nabble.com/Address-already-in-use--t3817771.html for the easy solution. No need for your workaround!

Jeroen Brattinga


Andre de C. Rodrigues wrote:
Hello,

I'm having a few concurrency problems in my project.

In my project, I have an IoHandler that binds to another port when it
receives it's first message. If another person connects to my program,
it has to close the previous connection before it binds to the same
port again, otherwise I'd get an exception stating "address already in
use". So, what I do is that I have a filter that detects a second
connection incoming and closes the previous connection. Obviously, the
previous connection has to be closed *before* the current connection
attempts to bind.

The thing is, session.close().join() does not work as expected: it
does not wait until the other session is closed before continuing with
the calling thread's execution, so the new session is not *always*
created only after the old session was closed.

I took some excerpts from my code to reproduce the error. Since I
don't know how you handle Attachments, I'll just paste my code here.
There are only 3 classes, and they are rather small =P.

Does anyone has any idea to fix or work around this?

Thanks in advance for the help, MINA is great.

Cheers.

PS: I'm using MINA 1.1

<snip>

Reply via email to