Commit edd0cf99 authored by Administrator's avatar Administrator

handle message TYPE_DESTROY

parent cb3842eb
...@@ -41,6 +41,10 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa ...@@ -41,6 +41,10 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa
case PacketCommon.C_TYPE_CONTROL: case PacketCommon.C_TYPE_CONTROL:
handleControlMessage(ctx, msg); handleControlMessage(ctx, msg);
break; break;
case PacketCommon.TYPE_DESTROY:
handleDestroyMessage(ctx);
break;
default: default:
EchoLogger.getLogger().warn("Unknown message type:" + msg.getType()); EchoLogger.getLogger().warn("Unknown message type:" + msg.getType());
break; break;
...@@ -48,6 +52,10 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa ...@@ -48,6 +52,10 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa
} }
private void handleDestroyMessage(ChannelHandlerContext ctx) {
ctx.close();
}
private void handleControlMessage(ChannelHandlerContext ctx, EchoPacket msg) { private void handleControlMessage(ChannelHandlerContext ctx, EchoPacket msg) {
long seq = msg.getSerialNumber(); long seq = msg.getSerialNumber();
String action = msg.getExtra(); String action = msg.getExtra();
...@@ -163,6 +171,9 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa ...@@ -163,6 +171,9 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx); super.channelInactive(ctx);
if (echoClient.isAlive()) {
return;
}
EchoLogger.getLogger().warn("client disconnected: " + ctx.channel() + " prepare to reconnect"); EchoLogger.getLogger().warn("client disconnected: " + ctx.channel() + " prepare to reconnect");
ctx.executor().schedule(new Runnable() { ctx.executor().schedule(new Runnable() {
@Override @Override
......
...@@ -40,6 +40,8 @@ public class PacketCommon { ...@@ -40,6 +40,8 @@ public class PacketCommon {
return "C_TYPE_CONTROL"; return "C_TYPE_CONTROL";
case TYPE_CONNECT_READY: case TYPE_CONNECT_READY:
return "TYPE_CONNECT_READY"; return "TYPE_CONNECT_READY";
case TYPE_DESTROY:
return "TYPE_DESTROY";
default: default:
return "UNKNOWN"; return "UNKNOWN";
} }
...@@ -84,5 +86,5 @@ public class PacketCommon { ...@@ -84,5 +86,5 @@ public class PacketCommon {
public static final byte TYPE_CONNECT_READY = 0x07; public static final byte TYPE_CONNECT_READY = 0x07;
// 销毁隧道 // 销毁隧道
public static final byte TYPE_DESTROT = 0x08; public static final byte TYPE_DESTROY = 0x08;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment