473,503 Members | 2,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Async NetworkStream: Problem With receiving large chunks of data


Hello,

I'm Writing my own NZb download App, using Async Network Streams en
Callback delegates. The Problem is that if I Want tot Receive Large
chunks of data (for instance the LIST NEWSGROUPS Response). I do not get
the Data at once.

Here is a piece of my source code:

I call the NetworkStream.ReadBegin as follows:
(ReadCallBack is the Call Back delegate)
byte[] ReadBuffer = new byte[100000];
stream.BeginRead(ReadBuffer, 0,
ReadBuffer.Length,ReadCallback,ReadBuffer);
And here is the Callback function:

protected void Stream_Read(IAsyncResult result)
{
int BytesRead = 0;
System.Text.ASCIIEncoding encoding = new
System.Text.ASCIIEncoding();

try
{
BytesRead = stream.EndRead(result);
}
catch (Exception e)
{

}
richTextBox1.Text +=
encoding.GetString((byte[])result.AsyncState, 0, BytesRead);

}
To get the full Response I have tot call the BeginRead Methode multiple
times, Currently I have to do it manually because I cant find a way to
check programmaticaly whether to call it again. Does anyone have A
solution for this problem ?

Thanks

Rogier

Jul 16 '07 #1
1 2456
On Mon, 16 Jul 2007 05:33:34 -0700, Rogier <Ro********@gmail.comwrote:
I'm Writing my own NZb download App, using Async Network Streams en
Callback delegates. The Problem is that if I Want tot Receive Large
chunks of data (for instance the LIST NEWSGROUPS Response). I do not get
the Data at once.
This is by design. A network stream is going to return data received as
soon as it has _some_ data, and necessarily wait until it has _all_ data.
This is true whether you use synchronous or asynchronous methods (other
than ReadToEnd(), of course).

You are required to use whatever information is available in the protocol
to indicate the length of the data, and read repeatedly until you have
enough data to process. Depending on the protocol, this could mean
receive a count of bytes in advance, looking for a delimiter at the end of
the data, or simply reading until the connection is closed.

Pete
Jul 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1960
by: Roemer | last post by:
Hey all While working with Async Methods and Networking I found something very strange or better a bug? To test it yourself create a new Windows Application with just a Button on the Form. ...
1
3338
by: hamid_2020 | last post by:
I wrote a class to connect to a server using tcpclient. I need to connect to the server and the connection must be open.Then i need to send request to the server again and again.But the problem is...
6
3798
by: Shak | last post by:
Hi all, Three questions really: 1) The async call to the networkstream's endread() (or even endxxx() in general) blocks. Async calls are made on the threadpool - aren't we advised not to...
7
2839
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets...
5
15688
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable...
4
3126
by: kreuters | last post by:
hey, can anyone explain to me why this method that is called numerous times to read chunks of a file works fine with a normal synchronous read, but causes a large memory leak when BeginRead() is...
0
1058
by: Laoujin | last post by:
Hi, I am receiving a XML file with embedded Base64 encoded file from a networkstream. What I would like to do is write the Base64 to a MemoryStream in chunks. Right now whenever I do a...
1
20547
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
1
4434
by: Almund | last post by:
Hi, I'm trying to implement streaming over http and got stuck with a problem trying to send chunks of data using the .Net NetworkStream object. All works fine as long as I send the entire data in...
0
7093
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
7291
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
7357
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
7468
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...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.