Connecting two server channels efficiently

Johnny Luong johnny.luong at trustcommerce.com
Wed Apr 28 18:17:58 EDT 2010


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



More information about the netty-users mailing list