473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

NetworkStream.Read troubles

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
1 1713
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cmjman | last post by:
I have an issue where networkStream.Write doesn't perform its write downstream from my client program until the network stream is closed. I then see the data that was sent appear on the other side....
4
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create...
1
by: kmacintyre | last post by:
I am trying to us a simple NetworkStream to transfer a file over tcp. This works most of the time, but one specific file never downloads(.mdb file). It seems to close the socket and I get an...
6
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream...
0
by: Al Wilkerson | last post by:
Hey, Has anyone ever got a "Unable to read data from transport connected" message after reading data from a streamreader composed of a networkstream. For example: Server TcpListener...
4
by: DaveR | last post by:
I have a background thread to accept and process TCP/IP connections. When the application shuts down I want to gracefully terminate it. The thread will block in NetworkStream.Read() waiting for...
5
by: | last post by:
I've got a basic "chat" infrastructure that can send objects across the wire, but I'm running into a few issues with trying to send multiple messages and things behaving differently in debug and...
3
by: shahla.saeed | last post by:
hi, plzz check my code and let me know where the problem is lying...becuase whenever i try to tansfer the file of 573KB(mp3) it just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time...
7
by: littleIO | last post by:
Hi, I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated. I have a server which listens, receives calls, processes them and sends back the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.