Using a client port range

Neil Avery neil at liquidlabs.co.uk
Mon Jun 7 07:55:16 EDT 2010


Hi Trustin,
On further testing - Ive discovered that the future is actually capturing
the exception in event of failure. I'd made the assumption that
channelFuture.await() would return false when an error condition was found.
Checking channelFuture.getCause() != null lets me determine failure.

Cheers, Neil.

On Mon, Jun 7, 2010 at 9:58 AM, Neil Avery <neil at liquidlabs.co.uk> wrote:

> Hi Trustin,
> My bad - I meant to say the channelFuture.await() returns true.
>
>          channelFuture = bootstrap.connect(remoteAddress, null);
>          boolean success =
> channelFuture.await(connectionEstablishTimeoutSecs, TimeUnit.SECONDS);
>
> Ill try and sort out a simple testcase.
> Cheers Neil.
>
>
> On Mon, Jun 7, 2010 at 3:49 AM, "Trustin Lee (이희승)" <trustin at gmail.com>wrote:
>
>> Hi Neil,
>>
>> ClientBootstrap.connect() does not return a boolean but returns a
>> ChannelFuture.  What property values does the returned ChannelFuture have?
>>
>> The stack trace you pasted tells me that the exception was not triggered
>> by write().  If you wrote something and it triggered the exception,
>> NioWorker should show up in the trace instead of
>> NioClientSocketPipelineSink.
>>
>> To make sure if this really is a Netty issue, could you please post a
>> very simple application that reproduces the problem?
>>
>> Thanks in advance,
>> Trustin
>>
>> Neil Avery wrote:
>> > 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 <http://www.liquidlabs.co.uk>
>> >
>> >
>> > ------------------------------------------------------------------------
>> >
>> > _______________________________________________
>> > netty-users mailing list
>> > netty-users at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/netty-users
>>
>> --
>> what we call human nature in actuality is human habit
>> http://gleamynode.net/
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
>>
>
>
>
> --
>
> www.liquidlabs.co.uk
>



-- 

www.liquidlabs.co.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20100607/f1419541/attachment.html 


More information about the netty-users mailing list