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

TcpServer使用UNPACK_BY_LENGTH_FIELD拆包规则,如何读取包头内容? #658

Open
mrclassfree opened this issue Dec 27, 2024 · 1 comment

Comments

@mrclassfree
Copy link

我使用TcpServer类,并使用UNPACK_BY_LENGTH_FIELD拆包规则,在包头中包含了包体长度和数据包ID还有数据包类型等字段。
然后我在onMessage(const hv::SocketChannelPtr& channel, hv::Buffer* buf) 回调中,需要读取包头的内容来做业务判断,因为数据发送端不是我写的,所以这个数据包协议我也改不了,所以请教一下,怎么读取包头的内容?

@ithewei
Copy link
Owner

ithewei commented Dec 27, 2024

使用setUnpack后,onMessage返回给你的就是完整的头部+数据的一包,你清楚头部格式,自己解析就好了,libhv做的只是帮你解决了"粘包"问题

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

2 participants