From 6511f7bad1c4f3cf342a21c1d68c5deb0e4ee80f Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@63.com> Date: 星期六, 30 七月 2022 13:03:41 +0800 Subject: [PATCH] # --- src/main/java/com/zy/core/netty/handle/ProtocolDecoder.java | 12 +++--------- src/main/java/com/zy/core/netty/handle/PackageServerHandler.java | 27 +-------------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java b/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java index 9c9f4fa..d91b1f1 100644 --- a/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java +++ b/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java @@ -3,13 +3,10 @@ import com.zy.core.netty.AbstractInboundHandler; import com.zy.core.netty.cache.ChannelCache; import com.zy.core.netty.domain.ChPackage; -import com.zy.core.netty.properties.TcpProperties; -import com.zy.core.properties.SlaveProperties; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -21,32 +18,10 @@ @ChannelHandler.Sharable public class PackageServerHandler extends AbstractInboundHandler<ChPackage> { - @Autowired - private SlaveProperties slaveProperties; - @Autowired - private TcpProperties tcpProperties; @Override protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) { - byte[] bytes = pac.getBytes(); - System.out.println("瀹㈡埛绔柇寮�===>>" + new String(bytes, 0, bytes.length)); - -// log.info("璇荤爜鍣ㄣ�怚P:{}銆� 涓婅鏁版嵁 ===>> {}", pac.getIp(), pac.getAscii()); -// //鎵爜涓婁紶鏁版嵁鏍煎紡蹇呴』2涓�#寮�澶达紝濡�:##12345678 -// String msg = pac.getAscii().replaceAll("#", ""); -// if(!Cools.isEmpty(msg) && msg.length()>=tcpProperties.getBarcodeLen()){ -// msg = msg.substring(0,tcpProperties.getBarcodeLen()); -// -// for (Slave slave : slaveProperties.getBarcode()) { -// if (slave.getIp().equals(pac.getIp())) { -// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, slave.getId()); -// if (barcodeThread == null) { continue; } -// barcodeThread.setBarcode(msg); -// break; -// } -// } -// } - + log.info("{}", pac.getBytes().length); return true; } diff --git a/src/main/java/com/zy/core/netty/handle/ProtocolDecoder.java b/src/main/java/com/zy/core/netty/handle/ProtocolDecoder.java index c265083..4b9cdeb 100644 --- a/src/main/java/com/zy/core/netty/handle/ProtocolDecoder.java +++ b/src/main/java/com/zy/core/netty/handle/ProtocolDecoder.java @@ -7,6 +7,7 @@ import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; +import lombok.extern.slf4j.Slf4j; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; @@ -15,6 +16,7 @@ /** * Created by vincent on 2019-04-10 */ +@Slf4j public class ProtocolDecoder extends ByteToMessageDecoder { private final SnowflakeIdWorker snowflakeIdWorker; @@ -26,22 +28,14 @@ @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> list) throws Exception { - byte[] bytes = new byte[in.readableBytes()]; - in.readBytes(bytes); - // 鐢熸垚鍜屽垵濮嬪寲娑堟伅鍖呰绫� - String ip = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress(); ChPackage pac = ChPackage.valueOfEmpty(String.valueOf(snowflakeIdWorker.nextId()), ip); pac.setSourceBuff(in); - pac.setBytes(bytes); - - list.add(pac); - // 瑙f瀽 -// list.add(analyzeProtocol(pac)); + list.add(analyzeProtocol(pac)); } public ChPackage analyzeProtocol(ChPackage pac){ -- Gitblit v1.9.1