Netty关闭客户端
生活随笔
收集整理的這篇文章主要介紹了
Netty关闭客户端
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在啟動(dòng)客戶端的時(shí)候,我們一般會(huì)
channelFuture.channel().closeFuture().sync();這是一段阻塞的代碼,除非鏈路斷了,否則是不會(huì)終止的,我們可以在handler中手動(dòng)關(guān)閉,達(dá)到關(guān)閉客戶端的效果
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;。。。。。。@Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {SubscribeResp subscribeResp = (SubscribeResp) msg;logger.debug("這是收到的第 " + (++count) + " 筆響應(yīng) -- " + subscribeResp);//關(guān)閉鏈路 ctx.close();}。。。。。。 }?
轉(zhuǎn)載于:https://www.cnblogs.com/sherrykid/p/6038672.html
總結(jié)
以上是生活随笔為你收集整理的Netty关闭客户端的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 军事测绘的基本比例尺地形图为1∶5万地形
- 下一篇: 军士一个月工资多少需要服役多久?