Re: Problems reading network stream
From: Alex Clark (alex_at_theclarkhome.spamtin.net)
Date: 01/07/05
- Next message: Dave: "Trying to better understand class design and types"
- Previous message: Samuel R. Neff: "Re: vb2005-like tab appearance"
- In reply to: rich_blum_at_juno.com: "Re: Problems reading network stream"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 7 Jan 2005 21:17:13 -0000
Thanks Rich,
It turns out it was a problem with the way I was decoding the byte-stream
into a string, if the entire buffer wasn't filled (which was often the case
for the last read of the stream) then it ended with CrLf.CrLf followed by
loads of Null chars, which were messing things up.
However, thanks for pointing out that other issue, you're quite right that
it could've caused the email to end unexpectedly if the end of a sentence
occurred at the end of one of the initial stream-reads. Thanks for that!
Kind Regards,
Alex Clark
<rich_blum@juno.com> wrote in message
news:1105123154.982303.201960@f14g2000cwb.googlegroups.com...
> Alex Clark wrote:
>>
>> I have a routine (posted below) which loops through the data in the
>> datastream, appending it to a string. It waits until it receives the
>
>> terminator, a "." followed by a CrLf. Unfortunately, it seems to be
>> "running out of steam" before the end of the message is downloaded.
>>
>> If waitForTerminator AndAlso (Not m_Stream.DataAvailable)
> AndAlso
>> (Not sResult.EndsWith("." & ControlChars.CrLf)) Then
>>
>
> Alex -
>
> Your logic will stop reading data from the stream as soon as the
> received buffer happens to end with a ".CrLf". This can happen any time
> a buffer ends with a complete sentence, without it being the end of the
> message.
>
> In POP, you know you are at the end of the message when you see
> "CrLf.CrLf" (a period on a line by itself). You should check for that
> condition instead.
>
> Alternatively, this is an excellent time to use the ReadLine()
> method in the StreamReader class. Just keep reading lines until you get
> one with only a period in it.
>
> Hope this helps solve your problem.
>
> Rich Blum - author
> "C# Network Programming" (Sybex)
> http://www.sybex.com/sybexbooks.nsf/Booklist/4176
>
- Next message: Dave: "Trying to better understand class design and types"
- Previous message: Samuel R. Neff: "Re: vb2005-like tab appearance"
- In reply to: rich_blum_at_juno.com: "Re: Problems reading network stream"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|