1.don't create new client bootstrap in the channelActive, create a client 
bootstrap at the application level, as same as the server bootstrap;
2.add the SomeOtherHandler to the client bootstrap pipeline;
3.after the client bootstrap connected to the remote server, save the 
ChannelHandlerContext in somewhere such as a global object;
4.when you want to send something to the remote server, use the 
ChannelHandlerContext you save in the global object

On Wednesday, May 17, 2017 at 11:16:03 PM UTC+8, crunc...@gmail.com wrote:
>
> Looking at Netty in Action and some SO posts, I saw that in order to talk 
> to another system, you can use Bootstrap() to create a new client and 
> attach it to the current eventLoop.  Looking at the proxy example, it's 
> done when the initial server is bootstrapped as well.  So I tried
>
>
> public void start(final ApplicationContext applicationContext) throws 
> Exception {
>         NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
>         NioEventLoopGroup workerGroup = new NioEventLoopGroup();
>
>         try {
>             bootstrap.group(bossGroup, 
> workerGroup).channel(NioServerSocketChannel.class)
>                     .handler(new 
> LoggingHandler(LogLevel.INFO)).childHandler(new 
> ChannelInitializer<SocketChannel>() {
>                         @Override
>                         protected void initChannel(SocketChannel ch) 
> throws Exception {
>                             ch.pipeline().addLast(new ServerHandlerImpl());
>                             ch.pipeline().addLast(new SomeOtherHandler());
>                         }
>
>                         @Override
>                         protected void channelActive(ChannelHandlerContext 
> ctx) throws Exception {
>                             Bootstrap clientBootstrap = new Bootstrap();
>                             clientBootstrap.channel(NioSocketChannel.class)
>                                     .handler(new 
> ChannelInitializer<SocketChannel>() {
>                                         @Override
>                                         protected void 
> initChannel(SocketChannel ch) throws Exception {
>                                             ch.pipeline().addLast(new 
> CredentialsClientHandler());
>                                         }
>                                     });
>                             
> clientBootstrap.group(ctx.channel().eventLoop());
>                             ChannelFuture future = 
> clientBootstrap.connect(host, port);
>                         }
>                     });
>
> So when a message comes in and it reaches the ServerHandlerImpl, I want it 
> to then route its message to CredentialsClientHandler that would send a 
> message to another server, check the credentials, and then resume the rest 
> of the pipeline.  In ServerHandlerImpl, how do I "send a message" down the 
> other handler and not down SomeOtherHandler?  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netty+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/4434bd76-4f4f-494b-8136-dca2e3ca81a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to