DataReader result truncated when reading from StreamSocket

I have the following C # / WinRT code to get 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);
}

      

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

+2


source to share


1 answer


The TCP / IP socket abstraction is a stream of bytes, not a stream of messages as I explain in my blog. Thus, it is perfectly normal to have a partial refund LoadAsync

after a partial message or any number of messages.

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



Anyway, what you are seeing is perfectly normal and acceptable for TCP / IP communication. You should loop on LoadAsync

(s ReadString

) until you find the end of your message. I think IMAP uses linefeeds for at least some of its message IDs. Typically you will have to handle situations where your message ends up in the middle of a line, but I think maybe it might skip this check for IMAP.

+2


source







All Articles