Using a client port range
Neil Avery
neil at liquidlabs.co.uk
Wed Jun 2 05:16:25 EDT 2010
Hi all,
Ive been given a requirement to make client ports run in a particular range.
Being the client side, it looks like java client sockets dont support the
SO_ADDR_REUSE in that client-sockets in TIMED_WAIT cannot be bound to - they
blow up with 'Address already in use'.
To overcome this problem, Ive had to resort to determining availability by
establishing a client socket connection to a server socket - not pretty -
but using a ServerSocket() with addressResult(false) doesn't work - its like
the flag is ignored and allows those ports to be reused. BTW - Im using jdk
sockets for the checking process.
The problem Ive encountered is when a race-state occurs and many client
socket connections start at the same time, it seems that the
bootstrap.connect(serverSocket,clientSocket) - is returning 'true'
indicating a connect success, however it turns out that the connection is
not completed so when the channel is used and I receive the exception
below. I would like the ability to know the connection was actually
successful/bound as a result of the connect future, so its possible to take
corrective action, rather than at the write state/stage.
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:574)
at
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:384)
at
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:354)
at
org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:276)
at
org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Its fairly eay to reproduce.... use netty to establish a client socket
connection on a port in a timed_wait state, and it will report
bootstrap.connect(remote,local) == true. Then when writing to the socket it
will fail with the above exception.
Regards Neil.
--
www.liquidlabs.co.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100602/22416061/attachment-0001.html
More information about the netty-users
mailing list