When you start the client, we generally
Channelfuture.channel (). Closefuture (). sync ();
This is a block of code, unless the link is broken, otherwise it will not be terminated, we can manually shut down in the handler, to achieve the effect of shutting down the client
Packageorg.zln.netty.five.part05.client;ImportIo.netty.channel.ChannelHandlerAdapter;ImportIo.netty.channel.ChannelHandlerContext;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;ImportOrg.zln.netty.five.part05.dto.SubscribeReq;ImportOrg.zln.netty.five.part05.dto.SubscribeResp;/*** Created by Sherry on 16/11/5.*/ Public classSubreqclienthandlerextendsChannelhandleradapter {/*** Log*/ PrivateLogger Logger = Loggerfactory.getlogger (Subreqclienthandler.class); Private Static intCount = 0; 。。。。。。 @Override Public voidChannelread (Channelhandlercontext ctx, Object msg)throwsException {subscriberesp subscriberesp=(SUBSCRIBERESP) msg; Logger.debug ("This is the received first" + (++count) + "pen response--" +Subscriberesp); //Close LinkCtx.close (); }。。。。。。 }
Netty shutting down the client