为啥netty超时netty 连接超时关闭不掉

标签:至少1个,最多5个
顾名思义, 所谓 心跳, 即在 TCP 长连接中, 客户端和服务器之间定期发送的一种特殊的数据包, 通知对方自己还在线, 以确保 TCP 连接的有效性.
为什么需要心跳
因为网络的不可靠性, 有可能在 TCP 保持长连接的过程中, 由于某些突发情况, 例如网线被拔出, 突然掉电等, 会造成服务器和客户端的连接中断. 在这些突发情况下, 如果恰好服务器和客户端之间没有交互的话, 那么它们是不能在短时间内发现对方已经掉线的. 为了解决这个问题, 我们就需要引入 心跳 机制. 心跳机制的工作原理是: 在服务器和客户端之间一定时间内没有数据交互时, 即处于 idle 状态时, 客户端或服务器会发送一个特殊的数据包给对方, 当接收方收到这个数据报文后, 也立即发送一个特殊的数据报文, 回应发送方, 此即一个 PING-PONG 交互. 自然地, 当某一端收到心跳消息后, 就知道了对方仍然在线, 这就确保 TCP 连接的有效性.
如何实现心跳
我们可以通过两种方式实现心跳机制:
使用 TCP 协议层面的 keepalive 机制.
在应用层上实现自定义的心跳机制.
虽然在 TCP 协议层面上, 提供了 keepalive 保活机制, 但是使用它有几个缺点:
它不是 TCP 的标准协议, 并且是默认关闭的.
TCP keepalive 机制依赖于操作系统的实现, 默认的 keepalive 心跳时间是 两个小时, 并且对 keepalive 的修改需要系统调用(或者修改系统配置), 灵活性不够.
TCP keepalive 与 TCP 协议绑定, 因此如果需要更换为 UDP 协议时, keepalive 机制就失效了.
虽然使用 TCP 层面的 keepalive 机制比自定义的应用层心跳机制节省流量, 但是基于上面的几点缺点, 一般的实践中, 人们大多数都是选择在应用层上实现自定义的心跳.既然如此, 那么我们就来大致看看在在 Netty 中是怎么实现心跳的吧. 在 Netty 中, 实现心跳机制的关键是 IdleStateHandler, 它可以对一个 Channel 的 读/写设置定时器, 当 Channel 在一定事件间隔内没有数据交互时(即处于 idle 状态), 就会触发指定的事件.
使用 Netty 实现心跳
上面我们提到了, 在 Netty 中, 实现心跳机制的关键是 IdleStateHandler, 那么这个 Handler 如何使用呢? 我们来看看它的构造器:
public IdleStateHandler(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) {
this((long)readerIdleTimeSeconds, (long)writerIdleTimeSeconds, (long)allIdleTimeSeconds, TimeUnit.SECONDS);
实例化一个 IdleStateHandler 需要提供三个参数:
readerIdleTimeSeconds, 读超时. 即当在指定的时间间隔内没有从 Channel 读取到数据时, 会触发一个 READER_IDLE 的 IdleStateEvent 事件.
writerIdleTimeSeconds, 写超时. 即当在指定的时间间隔内没有数据写入到 Channel 时, 会触发一个 WRITER_IDLE 的 IdleStateEvent 事件.
allIdleTimeSeconds, 读/写超时. 即当在指定的时间间隔内没有读或写操作时, 会触发一个 ALL_IDLE 的 IdleStateEvent 事件.
为了展示具体的 IdleStateHandler 实现的心跳机制, 下面我们来构造一个具体的EchoServer 的例子, 这个例子的行为如下:
在这个例子中, 客户端和服务器通过 TCP 长连接进行通信.
通信的报文格式是:
+--------+-----+---------------+
| Length |Type |
|"HELLO, WORLD" |
+--------+-----+---------------+
客户端每隔一个随机的时间后, 向服务器发送消息, 服务器收到消息后, 立即将收到的消息原封不动地回复给客户端.
若客户端在指定的时间间隔内没有读/写操作, 则客户端会自动向服务器发送一个 PING 心跳, 服务器收到 PING 心跳消息时, 需要回复一个 PONG 消息.
下面所使用的代码例子可以在我的
/yongshun/some_java_code 上找到.
根据上面定义的行为, 我们接下来实现心跳的通用部分 CustomHeartbeatHandler:
* @author xiongyongshun
* @version 1.0
* @created 16/9/18 13:02
public abstract class CustomHeartbeatHandler extends SimpleChannelInboundHandler&ByteBuf& {
public static final byte PING_MSG = 1;
public static final byte PONG_MSG = 2;
public static final byte CUSTOM_MSG = 3;
protected S
private int heartbeatCount = 0;
public CustomHeartbeatHandler(String name) {
this.name =
protected void channelRead0(ChannelHandlerContext context, ByteBuf byteBuf) throws Exception {
if (byteBuf.getByte(4) == PING_MSG) {
sendPongMsg(context);
} else if (byteBuf.getByte(4) == PONG_MSG){
System.out.println(name + " get pong msg from " + context.channel().remoteAddress());
handleData(context, byteBuf);
protected void sendPingMsg(ChannelHandlerContext context) {
ByteBuf buf = context.alloc().buffer(5);
buf.writeInt(5);
buf.writeByte(PING_MSG);
context.writeAndFlush(buf);
heartbeatCount++;
System.out.println(name + " sent ping msg to " + context.channel().remoteAddress() + ", count: " + heartbeatCount);
private void sendPongMsg(ChannelHandlerContext context) {
ByteBuf buf = context.alloc().buffer(5);
buf.writeInt(5);
buf.writeByte(PONG_MSG);
context.channel().writeAndFlush(buf);
heartbeatCount++;
System.out.println(name + " sent pong msg to " + context.channel().remoteAddress() + ", count: " + heartbeatCount);
protected abstract void handleData(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf);
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
// IdleStateHandler 所产生的 IdleStateEvent 的处理逻辑.
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent)
switch (e.state()) {
case READER_IDLE:
handleReaderIdle(ctx);
case WRITER_IDLE:
handleWriterIdle(ctx);
case ALL_IDLE:
handleAllIdle(ctx);
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.err.println("---" + ctx.channel().remoteAddress() + " is active---");
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.err.println("---" + ctx.channel().remoteAddress() + " is inactive---");
protected void handleReaderIdle(ChannelHandlerContext ctx) {
System.err.println("---READER_IDLE---");
protected void handleWriterIdle(ChannelHandlerContext ctx) {
System.err.println("---WRITER_IDLE---");
protected void handleAllIdle(ChannelHandlerContext ctx) {
System.err.println("---ALL_IDLE---");
类 CustomHeartbeatHandler 负责心跳的发送和接收, 我们接下来详细地分析一下它的作用. 我们在前面提到, IdleStateHandler 是实现心跳的关键, 它会根据不同的 IO idle 类型来产生不同的 IdleStateEvent 事件, 而这个事件的捕获, 其实就是在 userEventTriggered 方法中实现的.我们来看看 CustomHeartbeatHandler.userEventTriggered 的具体实现:
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent)
switch (e.state()) {
case READER_IDLE:
handleReaderIdle(ctx);
case WRITER_IDLE:
handleWriterIdle(ctx);
case ALL_IDLE:
handleAllIdle(ctx);
在 userEventTriggered 中, 根据 IdleStateEvent 的 state() 的不同, 而进行不同的处理. 例如如果是读取数据 idle, 则 e.state() == READER_IDLE, 因此就调用 handleReaderIdle 来处理它. CustomHeartbeatHandler 提供了三个 idle 处理方法: handleReaderIdle, handleWriterIdle, handleAllIdle, 这三个方法目前只有默认的实现, 它需要在子类中进行重写, 现在我们暂时略过它们, 在具体的客户端和服务器的实现部分时再来看它们.
知道了这一点后, 我们接下来看看数据处理部分:
protected void channelRead0(ChannelHandlerContext context, ByteBuf byteBuf) throws Exception {
if (byteBuf.getByte(4) == PING_MSG) {
sendPongMsg(context);
} else if (byteBuf.getByte(4) == PONG_MSG){
System.out.println(name + " get pong msg from " + context.channel().remoteAddress());
handleData(context, byteBuf);
在 CustomHeartbeatHandler.channelRead0 中, 我们首先根据报文协议:
+--------+-----+---------------+
| Length |Type |
|"HELLO, WORLD" |
+--------+-----+---------------+
来判断当前的报文类型, 如果是 PING_MSG 则表示是服务器收到客户端的 PING 消息, 此时服务器需要回复一个 PONG 消息, 其消息类型是 PONG_MSG.扔报文类型是 PONG_MSG, 则表示是客户端收到服务器发送的 PONG 消息, 此时打印一个 log 即可.
客户端部分
客户端初始化
public class Client {
public static void main(String[] args) {
NioEventLoopGroup workGroup = new NioEventLoopGroup(4);
Random random = new Random(System.currentTimeMillis());
Bootstrap bootstrap = new Bootstrap();
.group(workGroup)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer&SocketChannel&() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast(new IdleStateHandler(0, 0, 5));
p.addLast(new LengthFieldBasedFrameDecoder(, -4, 0));
p.addLast(new ClientHandler());
Channel ch = bootstrap.remoteAddress("127.0.0.1", 12345).connect().sync().channel();
for (int i = 0; i & 10; i++) {
String content = "client msg " +
ByteBuf buf = ch.alloc().buffer();
buf.writeInt(5 + content.getBytes().length);
buf.writeByte(CustomHeartbeatHandler.CUSTOM_MSG);
buf.writeBytes(content.getBytes());
ch.writeAndFlush(buf);
Thread.sleep(random.nextInt(20000));
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
workGroup.shutdownGracefully();
上面的代码是 Netty 的客户端端的初始化代码, 使用过 Netty 的朋友对这个代码应该不会陌生. 别的部分我们就不再赘述, 我们来看看 ChannelInitializer.initChannel 部分即可:
.handler(new ChannelInitializer&SocketChannel&() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast(new IdleStateHandler(0, 0, 5));
p.addLast(new LengthFieldBasedFrameDecoder(, -4, 0));
p.addLast(new ClientHandler());
我们给 pipeline 添加了三个 Handler, IdleStateHandler 这个 handler 是心跳机制的核心, 我们为客户端端设置了读写 idle 超时, 时间间隔是5s, 即如果客户端在间隔 5s 后都没有收到服务器的消息或向服务器发送消息, 则产生 ALL_IDLE 事件.接下来我们添加了 LengthFieldBasedFrameDecoder, 它是负责解析我们的 TCP 报文, 因为和本文的目的无关, 因此这里不详细展开.最后一个 Handler 是 ClientHandler, 它继承于 CustomHeartbeatHandler, 是我们处理业务逻辑部分.
客户端 Handler
public class ClientHandler extends CustomHeartbeatHandler {
public ClientHandler() {
super("client");
protected void handleData(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
byte[] data = new byte[byteBuf.readableBytes() - 5];
byteBuf.skipBytes(5);
byteBuf.readBytes(data);
String content = new String(data);
System.out.println(name + " get content: " + content);
protected void handleAllIdle(ChannelHandlerContext ctx) {
super.handleAllIdle(ctx);
sendPingMsg(ctx);
ClientHandler 继承于 CustomHeartbeatHandler, 它重写了两个方法, 一个是 handleData, 在这里面实现 仅仅打印收到的消息.第二个重写的方法是 handleAllIdle. 我们在前面提到, 客户端负责发送心跳的 PING 消息, 当客户端产生一个 ALL_IDLE 事件后, 会导致父类的 CustomHeartbeatHandler.userEventTriggered 调用, 而 userEventTriggered 中会根据 e.state() 来调用不同的方法, 因此最后调用的是 ClientHandler.handleAllIdle, 在这个方法中, 客户端调用 sendPingMsg 向服务器发送一个 PING 消息.
服务器部分
服务器初始化
public class Server {
public static void main(String[] args) {
NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
NioEventLoopGroup workGroup = new NioEventLoopGroup(4);
ServerBootstrap bootstrap = new ServerBootstrap();
.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer&SocketChannel&() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast(new IdleStateHandler(10, 0, 0));
p.addLast(new LengthFieldBasedFrameDecoder(, -4, 0));
p.addLast(new ServerHandler());
Channel ch = bootstrap.bind(12345).sync().channel();
ch.closeFuture().sync();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
服务器的初始化部分也没有什么好说的, 它也和客户端的初始化一样, 为 pipeline 添加了三个 Handler.
服务器 Handler
public class ServerHandler extends CustomHeartbeatHandler {
public ServerHandler() {
super("server");
protected void handleData(ChannelHandlerContext channelHandlerContext, ByteBuf buf) {
byte[] data = new byte[buf.readableBytes() - 5];
ByteBuf responseBuf = Unpooled.copiedBuffer(buf);
buf.skipBytes(5);
buf.readBytes(data);
String content = new String(data);
System.out.println(name + " get content: " + content);
channelHandlerContext.write(responseBuf);
protected void handleReaderIdle(ChannelHandlerContext ctx) {
super.handleReaderIdle(ctx);
System.err.println("---client " + ctx.channel().remoteAddress().toString() + " reader timeout, close it---");
ctx.close();
ServerHandler 继承于 CustomHeartbeatHandler, 它重写了两个方法, 一个是 handleData, 在这里面实现 EchoServer 的功能: 即收到客户端的消息后, 立即原封不动地将消息回复给客户端.第二个重写的方法是 handleReaderIdle, 因为服务器仅仅对客户端的读 idle 感兴趣, 因此只重新了这个方法. 若服务器在指定时间后没有收到客户端的消息, 则会触发 READER_IDLE 消息, 进而会调用 handleReaderIdle 这个方法. 我们在前面提到, 客户端负责发送心跳的 PING 消息, 并且服务器的 READER_IDLE 的超时时间是客户端发送 PING 消息的间隔的两倍, 因此当服务器 READER_IDLE 触发时, 就可以确定是客户端已经掉线了, 因此服务器直接关闭客户端连接即可.
使用 Netty 实现心跳机制的关键就是利用 IdleStateHandler 来产生对应的 idle 事件.
一般是客户端负责发送心跳的 PING 消息, 因此客户端注意关注 ALL_IDLE 事件, 在这个事件触发后, 客户端需要向服务器发送 PING 消息, 告诉服务器"我还存活着".
服务器是接收客户端的 PING 消息的, 因此服务器关注的是 READER_IDLE 事件, 并且服务器的 READER_IDLE 间隔需要比客户端的 ALL_IDLE 事件间隔大(例如客户端ALL_IDLE 是5s 没有读写时触发, 因此服务器的 READER_IDLE 可以设置为10s)
当服务器收到客户端的 PING 消息时, 会发送一个 PONG 消息作为回复. 一个 PING-PONG 消息对就是一个心跳交互.
实现客户端的断线重连
public class Client {
private NioEventLoopGroup workGroup = new NioEventLoopGroup(4);
public static void main(String[] args) throws Exception {
Client client = new Client();
client.start();
client.sendData();
public void sendData() throws Exception {
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i & 10000; i++) {
if (channel != null && channel.isActive()) {
String content = "client msg " +
ByteBuf buf = channel.alloc().buffer(5 + content.getBytes().length);
buf.writeInt(5 + content.getBytes().length);
buf.writeByte(CustomHeartbeatHandler.CUSTOM_MSG);
buf.writeBytes(content.getBytes());
channel.writeAndFlush(buf);
Thread.sleep(random.nextInt(20000));
public void start() {
bootstrap = new Bootstrap();
.group(workGroup)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer&SocketChannel&() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast(new IdleStateHandler(0, 0, 5));
p.addLast(new LengthFieldBasedFrameDecoder(, -4, 0));
p.addLast(new ClientHandler(Client.this));
doConnect();
} catch (Exception e) {
throw new RuntimeException(e);
protected void doConnect() {
if (channel != null && channel.isActive()) {
ChannelFuture future = bootstrap.connect("127.0.0.1", 12345);
future.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture futureListener) throws Exception {
if (futureListener.isSuccess()) {
channel = futureListener.channel();
System.out.println("Connect to server successfully!");
System.out.println("Failed to connect to server, try connect after 10s");
futureListener.channel().eventLoop().schedule(new Runnable() {
public void run() {
doConnect();
}, 10, TimeUnit.SECONDS);
上面的代码中, 我们抽象出 doConnect 方法, 它负责客户端和服务器的 TCP 连接的建立, 并且当 TCP 连接失败时, doConnect 会 通过 "channel().eventLoop().schedule" 来延时10s 后尝试重新连接.
客户端 Handler
public class ClientHandler extends CustomHeartbeatHandler {
public ClientHandler(Client client) {
super("client");
this.client =
protected void handleData(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) {
byte[] data = new byte[byteBuf.readableBytes() - 5];
byteBuf.skipBytes(5);
byteBuf.readBytes(data);
String content = new String(data);
System.out.println(name + " get content: " + content);
protected void handleAllIdle(ChannelHandlerContext ctx) {
super.handleAllIdle(ctx);
sendPingMsg(ctx);
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
client.doConnect();
断线重连的关键一点是检测连接是否已经断开. 因此我们改写了 ClientHandler, 重写了 channelInactive 方法. 当 TCP 连接断开时, 会回调 channelInactive 方法, 因此我们在这个方法中调用 client.doConnect() 来进行重连.
完整代码可以在我的
/yongshun/some_java_code 上找到.
本文由 yongshun 发表于个人博客, 采用署名-非商业性使用-相同方式共享 3.0 中国大陆许可协议.非商业转载请注明作者及出处. 商业转载请联系作者本人Email: 本文标题为: 浅析 Netty 实现心跳机制与断线重连本文链接为:
2 收藏&&|&&18
你可能感兴趣的文章
1 收藏,880
73 收藏,6.2k
本作品采用 署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
写的很详细!
请问下用buf.retain();的作用是什么
这个是我代码的笔误, 忽略吧.
翻译错误:allIdleTimeSeconds, 读/写超时. 即当在指定的事件间隔内既没有读又没有写操作时, 会触发一个 ALL_IDLE 的 IdleStateEvent 事件.
分享到微博?
技术专栏,帮你记录编程中的点滴,提升你对技术的理解收藏感兴趣的文章,丰富自己的知识库
明天提醒我
我要该,理由是:
扫扫下载 Appfrom:http://itindex.net/detail/54161-netty-client&当我们用Netty实现一个TCP client时,我们当然希望当连接断掉的时候Netty能够自动重连。&Netty Client有两种情况下需要重连:Netty Client启动的时候需要重连在程序运行中连接断掉需要重连。对于第一种情况,Netty的作者在stackoverflow上给出了&,&对于第二种情况,Netty的例子uptime中实现了一种&。而Thomas在他的&中提供了这两种方式的实现的例子。实现ChannelFutureListener 用来启动时监测是否连接成功,不成功的话重试:
public class Client
private EventLoopGroup loop = new NioEventLoopGroup();
public static void main( String[] args )
new Client().run();
public Bootstrap createBootstrap(Bootstrap bootstrap, EventLoopGroup eventLoop) {
if (bootstrap != null) {
final MyInboundHandler handler = new MyInboundHandler(this);
bootstrap.group(eventLoop);
bootstrap.channel(NioSocketChannel.class);
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
bootstrap.handler(new ChannelInitializer&SocketChannel&() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast(handler);
bootstrap.remoteAddress("localhost", 8888);
bootstrap.connect().addListener(new ConnectionListener(this));
public void run() {
createBootstrap(new Bootstrap(), loop);
}ConnectionListener 负责重连:
public class ConnectionListener implements ChannelFutureListener {
public ConnectionListener(Client client) {
this.client =
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
System.out.println("Reconnect");
final EventLoop loop = channelFuture.channel().eventLoop();
loop.schedule(new Runnable() {
public void run() {
client.createBootstrap(new Bootstrap(), loop);
}, 1L, TimeUnit.SECONDS);
}同样在ChannelHandler监测连接是否断掉,断掉的话也要重连:
public class MyInboundHandler extends SimpleChannelInboundHandler {
public MyInboundHandler(Client client) {
this.client =
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
final EventLoop eventLoop = ctx.channel().eventLoop();
eventLoop.schedule(new Runnable() {
public void run() {
client.createBootstrap(new Bootstrap(), eventLoop);
}, 1L, TimeUnit.SECONDS);
super.channelInactive(ctx);
}参考文档&
阅读(...) 评论()netty4,异常断线的问题. - ITeye问答
我写了个消息转发程序,也加了心跳处理,1分钟没读写操作的用户自动被踢下线.
可是现在遇到一个问题,如A用户要发送消息给B用户,通过服务器中转,
服务器在接收到A的消息时,B用户实际已经断网了(我把B用户的网线拔掉了),
这时服务器既然是不知道的.
ChannelFuture writeFuture = channel.write(msg);
final Channel sendChannel = ctx.channel();
writeFuture.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()){
sendChannel.write(JSONResult.getSuccess());
System.err.println("future.isSuccess()");
if (future.isDone()){
sendChannel.write(JSONResult.getSuccess());
System.err.println("future.isDone()");
if (future.isCancelled()){
sendChannel.write(JSONResult.getSuccess());
System.err.println("future.isCancelled()");
operationComplete都会返回成功..只有到了1分钟的时候,服务器才回把B用户踢下线.我要怎么才能在服务端判断B用户实际已经掉线了??
问题补充:谁来救救我啊~郁闷死了!
问题补充:难道netty过时没人用了?
采纳的答案
你这种情况属于正常的,没有问题。
客户端异常掉线,比如断开网线或者断电等情况下,客户端的channel对象不会自动关闭,所以才引入了心跳的机制,也就是服务器端通过监测在心跳期间内(1分钟)是否收到了客户端发过来的消息,来判断是否可以和客户端进行通信,如果没有收到任何消息,则视为客户端掉线。心跳机制就是为了解决你说的这个问题的。
不光是netty,所有基于socket的通信都有这个问题,因为客户端和服务端是基于消息的协议,只有客户端主动发出断开的消息给服务端,服务端才能明确知道客户端断开了连接,直接拔掉网线或者断电的情况下,属于底层的异常,客户端程序是根本监测不到的,即使你的客户端程序能够监测到,也没有用,因为此时网线已经被拔掉了,根本没法给服务端发送消息。所以服务端才引入了心跳机制来对应这种异常情况,相当于超时机制,超过规定时间没有接到消息,就视为客户端掉线了,以释放服务端的资源。
相当于两个人通话,对方突然把手机电池拔掉了,一点声音也没有,持续了1分钟,你这边肯定是不知道他那边出了什么状况,最后你肯定就挂机了,不可能傻等着,呵呵。
详细情况可以看一下下面的文章,里面有异常掉线的解释:
楼上给的很全,,楼主仔细研究下吧.不是很复杂的
已解决问题
未解决问题

我要回帖

更多关于 storm netty连接超时 的文章

 

随机推荐