How to try and cache all events in netty client?

21 views
Skip to first unread message

andyma...@gmail.com

unread,
Jul 22, 2016, 9:53:25 AM7/22/16
to Netty discussions
I found that if I just use Java try and cache to get exception, it is unavailable to cache netty's exception, so any methods to get exception for client connecting, client disconnecting, even writing? here is my netty client code:

        final String ip = "127.0.0.1";
        final int port = 9001;
        final EventLoopGroup g = new NioEventLoopGroup();
        final Bootstrap b = new Bootstrap();
        final ChannelFuture f = b.group(g)
                .channel(NioSocketChannel.class)
                .option(ChannelOption.TCP_NODELAY, true)
                .option(ChannelOption.SO_REUSEADDR, true)
                .option(ChannelOption.SO_KEEPALIVE, true)
                .handler(new EchoClientInitializer())
                .connect(ip, port)
                .sync();
        f.channel().closeFuture().sync();
        g.shutdownGracefully();

Thank!

Norman Maurer

unread,
Jul 22, 2016, 9:54:54 AM7/22/16
to ne...@googlegroups.com
All of the methods return a ChannelFuture for which you can add a ChannelFutureListener to get notified about success / error. You can also call sync() if you want to block but this is usually not what you want.

--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/cdbd14ce-38a0-4b17-ae65-5874b719a3a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages