|
@@ -1,5 +1,6 @@
|
|
|
package com.mes.ygsl;
|
|
package com.mes.ygsl;
|
|
|
|
|
|
|
|
|
|
+import com.mes.component.GunPanel;
|
|
|
import com.mes.ui.YgslUtil;
|
|
import com.mes.ui.YgslUtil;
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.channel.Channel;
|
|
import io.netty.channel.Channel;
|
|
@@ -24,16 +25,27 @@ public class YgslClientHandler extends ChannelInboundHandlerAdapter {
|
|
|
@Override
|
|
@Override
|
|
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
|
System.out.println("扭力枪" + gunIndex + "连接中:" + sdf.format(new Date()));
|
|
System.out.println("扭力枪" + gunIndex + "连接中:" + sdf.format(new Date()));
|
|
|
|
|
+
|
|
|
|
|
+ if (gunClient != null) {
|
|
|
|
|
+ GunPanel panel = gunClient.getGunPanel();
|
|
|
|
|
+ if (panel != null) {
|
|
|
|
|
+ panel.setOnline(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
|
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
|
|
Channel channel = ctx.channel();
|
|
Channel channel = ctx.channel();
|
|
|
- System.err.println("关闭扭力枪" + gunIndex + " TCP连接, IP:" + channel.remoteAddress());
|
|
|
|
|
|
|
+ String remoteAddr = channel.remoteAddress() != null ? channel.remoteAddress().toString() : "未知";
|
|
|
|
|
+ System.err.println("扭力枪" + gunIndex + " 连接断开, IP:" + remoteAddr);
|
|
|
channel.close();
|
|
channel.close();
|
|
|
|
|
|
|
|
- if (gunClient != null && gunClient.getGunPanel() != null) {
|
|
|
|
|
- gunClient.getGunPanel().setOnline(false);
|
|
|
|
|
|
|
+ if (gunClient != null) {
|
|
|
|
|
+ GunPanel panel = gunClient.getGunPanel();
|
|
|
|
|
+ if (panel != null) {
|
|
|
|
|
+ panel.setOnline(false);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|