Jelajahi Sumber

104Slaver中有某些通道连接可能不在连接池记录中,从而对连接状态判断异常,新增不在通道连接池内的连接通讯后关闭的功能

xiuwei 2 tahun lalu
induk
melakukan
754484b92e

+ 7 - 2
protocol-iec104/src/main/java/wei/yigulu/iec104/nettyconfig/Slave104Handle.java

@@ -8,6 +8,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
 import io.netty.channel.SimpleChannelInboundHandler;
 import lombok.NoArgsConstructor;
 import org.slf4j.Logger;
+import sun.awt.image.GifImageDecoder;
 import wei.yigulu.iec104.apdumodel.Apdu;
 import wei.yigulu.iec104.container.Iec104Link;
 import wei.yigulu.iec104.container.LinkContainer;
@@ -58,8 +59,12 @@ public class Slave104Handle extends SimpleChannelInboundHandler<ByteBuf> {
 		//收数据
 		log.debug("----------------------------------------------------------------------------------");
 		log.debug("re <= "+DataConvertor.ByteBuf2String( msg));
-		Apdu apdu = apduClass.newInstance().setChannel(ctx.channel()).setIec104Builder(slaverBuilder).setLog(slaverBuilder.getLog()).loadByteBuf(msg);
-		apdu.answer();
+		if (slaverBuilder.getChannels().contains(ctx.channel())){
+			Apdu apdu = apduClass.newInstance().setChannel(ctx.channel()).setIec104Builder(slaverBuilder).setLog(slaverBuilder.getLog()).loadByteBuf(msg);
+			apdu.answer();
+		}else{
+			ctx.channel().close();
+		}
 	}