从StreamSocket读取时的DataReader结果被截断 [英] DataReader result truncated when reading from StreamSocket

查看:489
本文介绍了从StreamSocket读取时的DataReader结果被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的C#/ WinRT的代码,即可获得从IMAP命令的响应

I have the following c# / WinRT code to receive a response from an IMAP command

DataReader reader = new DataReader(sock.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
await reader.LoadAsync(1000000);
string data = string.Empty;
while(reader.UnconsumedBufferLength > 0){
    data += reader.ReadString(reader.UnconsumedBufferLength);
}



结果后,8192字节截断。 8192看起来很像某种形式的限制。我该如何解决这个问题?

The results are truncated after 8192 bytes. 8192 looks suspiciously like a limit of some kind. How do I get around this?

推荐答案

TCP / IP套接字的抽象是一个字节流,而不是消息流的,因为我在我的博客解释。所以这是完全正常的有部分消息或任何数量的消息后,部分 LoadAsync 的回报。

The abstraction of TCP/IP sockets is a stream of bytes, not a stream of messages, as I explain on my blog. So it's perfectly normal to have a partial LoadAsync return after a partial message or any number of messages.

8192的声音像它可能是一个巨型帧(千兆以太网)。或者默认读一些.NET层的大小。

8192 sounds like it could be a jumbo frame (Gigabit Ethernet). Or perhaps the default read size of some .NET layer.

不管怎样,你看到的是TCP / IP通信完全正常的,可以接受的。你必须对 LoadAsync (和 ReadString )循环,直到你发现你的消息的结束。我觉得IMAP使用换行,至少的部分的它的消息定界符的。通常情况下,你必须处理您的消息将在一个字符串中间结束的情况下,但我的认为的可能也许可以跳过此检查的IMAP。

Anyway, what you're seeing is perfectly normal and acceptable for TCP/IP communications. You have to loop on LoadAsync (and ReadString) until you detect the end of your message. I think IMAP uses linefeeds, at least for some of its message delimeters. Normally, you'd have to handle situations where your message would end in the middle of a string, but I think may might be able to skip this check for IMAP.

这篇关于从StreamSocket读取时的DataReader结果被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆