473,588 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asynchronous network stream reading issue

Hello,

I have a program that asynchronously reads data from a host. However,
whenever I call the BeginRead function, the async reading "loop" never seems
to terminate. Why doesn't the EndRead method return 0 when it is done
reading??

This is the pseudo-code for my callback function:

ReadData
numbytes = EndRead

if numbytes > 0 then
do stuff with new chunk of data

BeginRead
end if

end ReadData

For some reason, the numbytes is always greater than 0 which causes two
major problems; one is that it keeps reading, so when I try to close the
connection, an exception is thrown, and the other is that the *first* time I
call BeginRead, it keeps reading (although it shouldn't).

Thanks for shedding any light on this subject.

--
Regards,
Webster

P.S. There was an earlier thread with pretty much the exact same problem,
but his fix didn't seem to work for me for some reason *_*

article 159535
Subject: Asynchronous TCP/IP
Date: Tue, 18 Nov 2003 23:32:02 GMT
Nov 20 '05 #1
0 1007

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

Similar topics

5
2424
by: localhost | last post by:
Network socket client code works correctly: byte nameBytes = new byte; recvData = inStream.Read( nameBytes , 0 , 1024 ); string fileNameRaw = System.Text.Encoding.UTF8.GetString( nameBytes ); string fileName = fileNameRaw.Substring( 0 , fileNameRaw.IndexOf("***") ); Console.WriteLine( fileName );
1
6209
by: Niels Johansen | last post by:
Hello, When using the asynchronous read method in the BufferedStream class, , it seems to me that it blocks like the normal synchronous read method. Why is it so? Why does the BufferedStream.BeginRead() not behave similar to the NetworkStream.BeginRead() ?? The following short program illustrates my problem.: using System;
3
2455
by: Alex Clark | last post by:
Hi All, I'm having some problems reading a network stream. I'm writing a lightweight POP client to handle a very specific task, but I keep unexpectedly reaching the end of the datastream when downloading a large-ish email (about 10K). This happens about 50% of the time when trying to download a large email from my POP server. I've tried telnet'ing into the POP server and manually issuing commands, and it works perfectly --- the...
5
5581
by: archana | last post by:
Hi all i am having application which is using asychronous web request. At a time i am processing 5 urls asynchronously. Application working properly for 5 asynchronous call. But sometimes CPU usage suddently increases to 100 %. Can some one tell me why this is happening.
3
6756
by: Sir Psycho | last post by:
Hi, For some reason, when i step over this code, it returns the full byte stream im expecting from the server, however when I let it run with no intervention, it only seems to grab a small chunk on the stream. What am I doing wrong? There is more code than this, but this is the problem code.
6
6990
by: Pat B | last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol using C#. I have implemented it using BeginReceive and EndReceive calls so as not to block when waiting for data from the supernode. Everything I have written works fine sending and receiving uncompressed data. But now I want to implement compression using the deflate algorithm as the Gnutella protocol accepts: Accept-Encoding: deflate Content-Encoding: deflate in the...
7
7668
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort() on the request object on another thread, GetResponse() returns with an exception as expected. However, when I monitor the network traffic, it does not seem to stop, but to continue to be active and to upload the file. The network is active even...
2
3415
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when failing to asynchronously connect sockets on closed or filtered ports, but I'm quite unsure if this is a PHP issue or my misunderstanding, as it seems that socket streams only wrap around <sys/socket.h>.
1
7143
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN site, which is actually for sending strings. I tried to adapt this code so that the client sends an image instead of a string. However, there is something wrong on the server side (i guess)... The server starts listening, the client starts sending...
0
7862
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
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
8357
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...
0
6634
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...
1
5729
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
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...
0
3887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1196
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.