473,657 Members | 2,266 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.R eadBegin as follows:
(ReadCallBack is the Call Back delegate)
byte[] ReadBuffer = new byte[100000];
stream.BeginRea d(ReadBuffer, 0,
ReadBuffer.Leng th,ReadCallback ,ReadBuffer);
And here is the Callback function:

protected void Stream_Read(IAs yncResult result)
{
int BytesRead = 0;
System.Text.ASC IIEncoding encoding = new
System.Text.ASC IIEncoding();

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

}
richTextBox1.Te xt +=
encoding.GetStr ing((byte[])result.AsyncSt ate, 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 2469
On Mon, 16 Jul 2007 05:33:34 -0700, Rogier <Ro********@gma il.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
1970
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. Then modify the Code of the Form1 class until it looks like:
1
3348
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 that i can communicate with the servet just for one time,the first time i connect to the server,send data and receive response,but when i want to receive data for another time,there won't be any response.some body help me please,whats the problem???...
6
3813
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 cause these to block? 2) You can connect together a binaryreader to a networkstream:
7
2851
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 send the messagetype via async NetworkStream ns = client.GetStream(); //assume client globally accessible
5
15714
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 to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for weeks, but I can't detect where it's
4
3138
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 called instead? private double ReadChunk(FileStream fileReader, int readLength, int channel) { short currentShort;
0
1066
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 NetworkStream.Read, it blocks until it has read everything. I would like it to read the first X characters, check if it is already on the Base64 (I am throwing away all the wrapping XML) and stream it to the MemoryStream directly instead of first reading...
1
20608
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 I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call to WSACancelBlockingCall"
1
4449
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 one invocation to the NetworkStream, like: _stream.Write(buffer, 0, buffer.Length) But if i try:
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2739
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.