Connecting two server channels efficiently

Johnny Luong johnny.luong at trustcommerce.com
Fri Apr 30 15:17:25 EDT 2010


Eric Bouer wrote:
> On Thursday 29 April 2010 01:17:58 Johnny Luong wrote:
>> beric wrote:
>>> Hello list of a very nice project.
>>> I'm trying to bridge two listening sockets so that any data on each of
>>> them will reach the other. the UNIX way is: "cat fifo | nc -l -p 3344 |
>>> nc -l -p 3355 > fifo" Now help me figure the Netty way :)
>>>
>>> My current way of doing that is by having 2 ServerBootstrap, while one of
>>> them(foo) has a SimpleChannelUpstreamHandler that has access to the
>>> pipeline of the other ServerBootstrap(bar) by holding a ChannelPiple
>>> member.
>>>
>>> Then, in channelOpen I'm trying to add an OutboundHAndler(from
>>> HexDumpProxy) to the channelpipeline of bar.
>>>
>>> It looks like this:
>>>  @Override
>>>  
>>>     public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent
>>>     e)
>>>
>>> throws Exception {
>>>
>>>     //Suspend incoming traffic
>>>     final Channel inboundChannel = e.getChannel();
>>>     inboundChannel.setReadable(false);
>>>     this.sb2piChannelPipeline.addLast("handler-sb2", new
>>>
>>> OutboundHandler(e.getChannel()));
>>>
>>>     }
>>>
>>> However I get a IllegalArgumentException : Duplicate handler name.
>>> I guess I did something wrong. I would like to know why, or any (probably
>>> better) alternative implementation of what I'm trying to do here.
>>> Thanks.
>> Would it make more sense just to have a ChannelGroup (add each new
>> incoming channel to the set) for each listener and then within each
>> handler, have it write to the appropriate channelgroup what that
>> individual channel received?
>>
>> Best,
>> Johnny
>>
>> _______________________________________________
>> netty-users mailing list
>> netty-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> I'm not sure I'm right but if I'll write to that ChannelGroup you mentioned 
> I'll get an "echo" effect when  data arrives . I don't want that.
> Am I right ?
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> 

Well it wouldn't echo back to the one who sent the data; if listener #1
had access to listener #2 channelgroup, then when the handler
(messagereceived) from listener #1 is invoked, you would be sending that
to listener #2 channelgroup.  The same would apply if you swap the
numbers around above.  In any case, I think maybe some details on the
problem would help.

-Johnny


More information about the netty-users mailing list