20260116:统一netty版本与使用7e做数据分隔符

This commit is contained in:
zhugongping 2026-01-16 15:15:25 +08:00
parent d8c7c19367
commit 4a03bac06b
2 changed files with 4 additions and 5 deletions

View File

@ -49,10 +49,9 @@ public class TCPBootStrap {
.setIdleStateTime(keepAlive, 0, 0)
.setPort(port)
//设置报文最大长度 modbus-rtu
.setMaxFrameLength(2048)
// 注意:0x7E 是注册/心跳帧(7E...7E)的帧头/帧尾,不能作为“分隔符”strip 掉,否则会导致吞掉帧头形成 0x80...7E 的残帧。
// 分隔符仅作为兜底(当既不是7E帧也不是Modbus RTU帧时),这里使用 '\n' 方便切分设备可能上报的ASCII日志行。
.setDelimiters(new Delimiter(new byte[]{0x0A}, true))
.setMaxFrameLength(1024)
// 此处就是ASCII和注册包粘包了,无需strip掉 “分隔符” 即可
.setDelimiters(new Delimiter(new byte[]{0x7e}, false))
.setDecoder(messageAdapter)
.setEncoder(messageAdapter)
.setHandlerMapping(handlerMapping)

View File

@ -32,7 +32,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <!-- Use 'netty-all' for 4.0 or above -->
<version>4.1.56.Final</version>
<!-- <version>4.1.56.Final</version>--> <!-- 直接使用sprinboot依赖项里面的版本号 -->
<scope>compile</scope>
</dependency>