Commit edd0cf99 authored by Administrator's avatar Administrator

handle message TYPE_DESTROY

parent cb3842eb
......@@ -41,6 +41,10 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa
case PacketCommon.C_TYPE_CONTROL:
handleControlMessage(ctx, msg);
break;
case PacketCommon.TYPE_DESTROY:
handleDestroyMessage(ctx);
break;
default:
EchoLogger.getLogger().warn("Unknown message type:" + msg.getType());
break;
......@@ -48,6 +52,10 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa
}
private void handleDestroyMessage(ChannelHandlerContext ctx) {
ctx.close();
}
private void handleControlMessage(ChannelHandlerContext ctx, EchoPacket msg) {
long seq = msg.getSerialNumber();
String action = msg.getExtra();
......@@ -163,6 +171,9 @@ public class EchoClientChannelHandler extends SimpleChannelInboundHandler<EchoPa
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
if (echoClient.isAlive()) {
return;
}
EchoLogger.getLogger().warn("client disconnected: " + ctx.channel() + " prepare to reconnect");
ctx.executor().schedule(new Runnable() {
@Override
......
......@@ -40,6 +40,8 @@ public class PacketCommon {
return "C_TYPE_CONTROL";
case TYPE_CONNECT_READY:
return "TYPE_CONNECT_READY";
case TYPE_DESTROY:
return "TYPE_DESTROY";
default:
return "UNKNOWN";
}
......@@ -84,5 +86,5 @@ public class PacketCommon {
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