By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,286 Members | 1,632 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,286 IT Pros & Developers. It's quick & easy.

NetworkStream.Read troubles

P: n/a
Need a little help with reading from a network stream. I'm downloading
articles from an NNTP server. The end of an article is signified by
<CRLF>.<CRLF>

For all the talking back & forth, I used a regular StreamReader &
StreamWriter. This works great except when i'm downloading a yEncoded binary
article. So I have to use the NetworkStream object. However, it's not so
easy now to know when I've hit the end of the article. Here's the code I'm
trying to use:

Dim buf(1024) As Byte
Dim fs As New FileStream(FileName, FileMode.Create)
Dim ns As NetworkStream = _NNTPClient.GetStream
Do
Dim x As Integer = ns.Read(buf, 0, buf.Length)
fs.Write(buf, 0, x)
Loop While ns.DataAvailable = True
fs.Close()

I never get more than 2 or 3 Kb's of an article before the loop ends because
DataAvailable is False. I found that if I put a messagebox in the loop and
click on it each time it pops up, I get the entire article. I don't want to
put an artificial delay in the loop (such as a sleep statement), but I can't
figure out how to get all of the article.

Is there a method for scanning the incoming data for the <CRLF>.<CRLF>
pattern?

..

..
Jul 8 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sat, 7 Jul 2007 23:46:07 -0600, "Terry Olsen"
<to******@hotmail.comwrote:
>Need a little help with reading from a network stream. I'm downloading
articles from an NNTP server. The end of an article is signified by
<CRLF>.<CRLF>

For all the talking back & forth, I used a regular StreamReader &
StreamWriter. This works great except when i'm downloading a yEncoded binary
article. So I have to use the NetworkStream object. However, it's not so
easy now to know when I've hit the end of the article. Here's the code I'm
trying to use:

Dim buf(1024) As Byte
Dim fs As New FileStream(FileName, FileMode.Create)
Dim ns As NetworkStream = _NNTPClient.GetStream
Do
Dim x As Integer = ns.Read(buf, 0, buf.Length)
fs.Write(buf, 0, x)
Loop While ns.DataAvailable = True
fs.Close()

I never get more than 2 or 3 Kb's of an article before the loop ends because
DataAvailable is False. I found that if I put a messagebox in the loop and
click on it each time it pops up, I get the entire article. I don't want to
put an artificial delay in the loop (such as a sleep statement), but I can't
figure out how to get all of the article.

Is there a method for scanning the incoming data for the <CRLF>.<CRLF>
pattern?
DataAvailable tells you whether or not data has been received by the
TCP stack that you haven't read yet, it doesn't tell you anything
about whether or not more data will arrive in the future.

There is a thread about this here:
http://www.dotnet247.com/247referenc...52/262200.aspx
Jul 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.