如何解决第 3 个消息帧的 RSocket Net pipereader.ReadAsync 被截断,导致 MessageFramePeek 方法出错
我使用 RSocket.Net 作为 Java Spring Boot RSocket 服务器的网络客户端。服务器将报价消息发送回客户端。示例代码一直工作到第 3 条引用消息,该消息被截断。
static public async Task Handler(IRSocketProtocol sink,PipeReader pipereader,CancellationToken cancellation)
{
Logs.Enter();
//The original implementation was a state-machine parser with resumability. It doesn't seem like the other implementations follow this pattern and the .NET folks are still figuring this out too - see the internal JSON parser discussion for how they're handling state machine persistence across async boundaries when servicing a Pipeline. So,this version of the handler only processes complete messages at some cost to memory buffer scalability.
//Note that this means that the Pipeline must be configured to have enough buffering for a complete message before source-quenching. This also means that the downstream consumers don't really have to support resumption,so the interface no longer has the partial buffer methods in it.
while (!cancellation.IsCancellationRequested)
{
var read = await pipereader.ReadAsync(cancellation);
var buffer = read.Buffer;
第一条消息是这样的,缓冲区大小为 942
下一条消息类似。那么第 3 条消息要么是 5657 的太大了!!?
或者它在 165 时太小了
这会导致 MessageFramePeek
方法出错
static public (int Length,bool IsEndOfMessage) MessageFramePeek(ReadOnlySequence<byte> sequence) { var reader = new SequenceReader<byte>(sequence); return reader.TryRead(out byte b1) && reader.TryRead(out byte b2) && reader.TryRead(out byte b3) ? ((b1 << 8 * 2) | (b2 << 8 * 1) | (b3 << 8 * 0),true) : (0,false); }
UPDATE 我检查了服务器和客户端上的编码类型是 JSON,以便字符串不会与线路上的对象混合。仍然存在同样的问题。
UPDATE 如果 RSocket.Core 构建在网络标准或网络框架上,则会发生同样的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。