标签:close 启动 debug text port ogg tty client handle
在启动客户端的时候,我们一般会
channelFuture.channel().closeFuture().sync();
这是一段阻塞的代码,除非链路断了,否则是不会终止的,我们可以在handler中手动关闭,达到关闭客户端的效果
package org.zln.netty.five.part05.client; import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.zln.netty.five.part05.dto.SubscribeReq; import org.zln.netty.five.part05.dto.SubscribeResp; /** * Created by sherry on 16/11/5. */ public class SubReqClientHandler extends ChannelHandlerAdapter { /** * 日志 */ private Logger logger = LoggerFactory.getLogger(SubReqClientHandler.class); private static int count = 0; 。。。。。。 @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { SubscribeResp subscribeResp = (SubscribeResp) msg; logger.debug("这是收到的第 " + (++count) + " 笔响应 -- " + subscribeResp); //关闭链路 ctx.close(); } 。。。。。。 }
标签:close 启动 debug text port ogg tty client handle
原文地址:http://www.cnblogs.com/sherrykid/p/6038672.html