Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline版本怎么集成LengthFieldBasedFrameDecoder协议? #11

Closed
491134648 opened this issue Apr 3, 2020 · 8 comments
Closed

Comments

@491134648
Copy link

Pipeline版本怎么集成LengthFieldBasedFrameDecoder协议,调试代码的时候发现不是正确包的时候,抛出了相关异常,下次再发数据包时就进入了Write了,然后就断开了连接,是为什么呢?

@SmallChi
Copy link
Owner

SmallChi commented Apr 3, 2020

额,这个可以参考下SuperSocket的LengthFieldBasedFrameDecoder,因为808没有用到固定长度的包,这边也没有打算在808下支持多协议的骚操作。😄

@491134648
Copy link
Author

这地方为什么要移除会话呢?SessionManager.RemoveBySessionId(session.SessionID);
public Task StartAsync(CancellationToken cancellationToken) { Logger.LogInformation($"JT808 TCP Server start at {IPAddress.Any}:{Configuration.TcpPort}."); Task.Factory.StartNew(async () => { while (!cancellationToken.IsCancellationRequested) { var socket = await server.AcceptAsync(); JT808TcpSession jT808TcpSession = new JT808TcpSession(socket); SessionManager.TryAdd(jT808TcpSession); await Task.Factory.StartNew(async (state) => { var session = (JT808TcpSession)state; if (Logger.IsEnabled(LogLevel.Information)) { Logger.LogInformation($"[Connected]:{session.Client.RemoteEndPoint}"); } var pipe = new Pipe(); Task writing = FillPipeAsync(session, pipe.Writer); Task reading = ReadPipeAsync(session, pipe.Reader); await Task.WhenAll(reading, writing); SessionManager.RemoveBySessionId(session.SessionID); }, jT808TcpSession); } }, cancellationToken); return Task.CompletedTask; }

@SmallChi
Copy link
Owner

SmallChi commented Apr 3, 2020

因为tcp这时候已经断开了,所以要移除掉。

@491134648
Copy link
Author

这个实际是没有断开,只是发的数据包格式不符合数据包规范,你可以发个错误包看下

@SmallChi
Copy link
Owner

SmallChi commented Apr 3, 2020

对呀,你都说了发了错误的包,那对于协议来说,肯定是不允许的,那只能是拒绝连接了。

@491134648
Copy link
Author

好吧,这个现实场景也会有网络干扰吧,比如信号强度不好的地方。

@SmallChi
Copy link
Owner

SmallChi commented Apr 3, 2020

网络问题,顶多就是断开重连,设备是有补传数据的,这都是正常的。

@SmallChi SmallChi closed this as completed Apr 3, 2020
@yedajiang44
Copy link
Collaborator

@491134648 DotNetty可以通过继承ByteToMessageDecoder,然后实现Decode的方法中根据协议规则去判断是哪种协议,并添加相应的handler即可,多协议归根结底还是handler的增加、删除、切换而已

注意:ChildHandler中只需要添加你实现的ByteToMessageDecoder,否则你需要做额外的工作

最后祝君好运~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants