Re: Problems reading network stream

From: Alex Clark (alex_at_theclarkhome.spamtin.net)
Date: 01/07/05


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
>



Relevant Pages

  • Re: HTTP Object and Retrieving HTML Programatically
    ... I had to hardcode some query string and form post values, ... chunks defined by the buffer size ... //create a stream reader grabbing text we get over HTTP ... while (workingbuffersize> 0) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: HLALib
    ... string buffers, and also "static dynamic strings", eg. static string ... ;function returns after reading one line, which can be less than size ... from any type of stream, so they never should access more than needed. ... line, stores it in buffer, and text parsing routine never reads more ...
    (alt.lang.asm)
  • Re: Possible to put stream character data into a string without creating a temporary fixed-sized
    ... I do a webrequest and it returns some text data in a stream. ... put this text data into a string. ... This fixed size buffer wastes ... Dim enc As New System.Text.ASCIIEncoding ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to read a stream into a buffer of non-fixed size?
    ... I want to read a string a chars from a stream, ... At the moment, I'm creating a buffer of a fixed size, and reading the ... stream of text into it. ... The response is most likely not encoded as ASCII, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Question about design, defmacro, macrolet, and &environment
    ... "Expects to find the literal string on the stream." ... (defun send (string &optional stream) ... (declaim (inline make-adjustable-string)) ...
    (comp.lang.lisp)

Quantcast