473,773 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Waiting

Hi,

I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try to recieve, no response has returned. I'm assuming that this is because the server hasn't had the chance to respond before the recieve buffer is read. If this is the case, then how do I tell my code to wait around before checking the stream?

If I just have a do{}until loop constantly checking the stream will this eat up the processor?
Is there a simple way of telling the code to wait for a few ticks?
Is there some way I can check the TcpClient or NetworkStream to see when to retrieve my data?

Any help?
Cheers,
Burns
Nov 15 '05 #1
7 2010
> this eat up the processor? Is there a simple way of telling the code
to wait for a few ticks? Is there some way I can check the TcpClient


Search the docs before you ask. The function you want is called Sleep().
As to which class it's in, well you'll have to find out. Try the help
system, it's useful.

--
gabriel
Nov 15 '05 #2
Burns,

Maybe you could fire an event when data is received?

Marco
"Burns" <an*******@disc ussions.microso ft.com> wrote in message
news:85******** *************** ***********@mic rosoft.com...
Hi,

I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try
to recieve, no response has returned. I'm assuming that this is because the
server hasn't had the chance to respond before the recieve buffer is read.
If this is the case, then how do I tell my code to wait around before
checking the stream?
If I just have a do{}until loop constantly checking the stream will this eat up the processor? Is there a simple way of telling the code to wait for a few ticks?
Is there some way I can check the TcpClient or NetworkStream to see when to retrieve my data?
Any help?
Cheers,
Burns

Nov 15 '05 #3
Hi Burns,

"Burns" <an*******@disc ussions.microso ft.com> wrote in message
news:85******** *************** ***********@mic rosoft.com...
Hi,

I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try
to recieve, no response has returned. I'm assuming that this is because the
server hasn't had the chance to respond before the recieve buffer is read.
If this is the case, then how do I tell my code to wait around before
checking the stream?
If I just have a do{}until loop constantly checking the stream will this eat up the processor? Is there a simple way of telling the code to wait for a few ticks?
Is there some way I can check the TcpClient or NetworkStream to see when

to retrieve my data?

I haven't had the opportunity to program a sockets-based app, so I'm not
a expert, but have you tried the BeginRead/BeginWrite methods. I believe
they use async completion ports, which, as I understand it, are the most
efficient way to do async messaging.

Regards,
Dan
Nov 15 '05 #4
Using a NetworkStream, the read() method should block until data is
available to read. However, you may be reading only one or two bytes at a
time. You should make sure to try and keep "read()"ing until the full
response has been pulled down. If you do want to delay a bit, call
System.Threadin g.Thread.Sleep( ... );
"Burns" <an*******@disc ussions.microso ft.com> wrote in message
news:85******** *************** ***********@mic rosoft.com...
Hi,

I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try
to recieve, no response has returned. I'm assuming that this is because the
server hasn't had the chance to respond before the recieve buffer is read.
If this is the case, then how do I tell my code to wait around before
checking the stream?
If I just have a do{}until loop constantly checking the stream will this eat up the processor? Is there a simple way of telling the code to wait for a few ticks?
Is there some way I can check the TcpClient or NetworkStream to see when to retrieve my data?
Any help?
Cheers,
Burns

Nov 15 '05 #5

"Burns" <an*******@disc ussions.microso ft.com> wrote in message
news:85******** *************** ***********@mic rosoft.com...
Hi,

I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try
to recieve, no response has returned. I'm assuming that this is because the
server hasn't had the chance to respond before the recieve buffer is read.
If this is the case, then how do I tell my code to wait around before
checking the stream?
If I just have a do{}until loop constantly checking the stream will this eat up the processor? Is there a simple way of telling the code to wait for a few ticks?
Is there some way I can check the TcpClient or NetworkStream to see when to retrieve my data?
Any help?


Are you flushing the writestream after you send data?

ie:

streamWriter.Wr iteLine("some command");
streamWriter.Fl ush();

string response = streamReader.Re adLine();

(assumming these are the stream reader/writer you obtained from the network
stream of course).

I have exactly the same problem you described (apparently no data being
returned from the server). It wasn't untill I hooked up a sniffer I
realised the server wasn't responding as it hadn't recieved the command.

Alan
Nov 15 '05 #6
Normally, you don't need any special code to wait because Read will block
until data is available. And the wait done internally by Read is more
efficient than what you would program (it waits on some kernel object and
lets other processes/threads use the CPU until the kernel object is
signalled).

But you have to make sure that you Flush your output before calling Read.
Otherwise, your output will remain in buffers and the server won't get it.
So, you're likely to run into some kind of hung state (server waiting for
your output which is buffered, you waiting for the server's response) if you
forget to Flush.

Bruno.

"Burns" <an*******@disc ussions.microso ft.com> a écrit dans le message de
news:85******** *************** ***********@mic rosoft.com...
Hi,

I'm writing some code that talks to a POP3 server with a TcpClient. I can send and receive using a NetworkStream, but when I send my message, then try
to recieve, no response has returned. I'm assuming that this is because the
server hasn't had the chance to respond before the recieve buffer is read.
If this is the case, then how do I tell my code to wait around before
checking the stream?
If I just have a do{}until loop constantly checking the stream will this eat up the processor? Is there a simple way of telling the code to wait for a few ticks?
Is there some way I can check the TcpClient or NetworkStream to see when to retrieve my data?
Any help?
Cheers,
Burns

Nov 15 '05 #7
to gabriel:

And you should think first, and then reply.
Using Sleep is definitely not the right approach here.
Well the right approach, I'm not gonna tell, and you ain't gonna find it in
the help files.

"gabriel" <no@no--spam.com> wrote in message
news:91******** *************** ****@msgid.mega newsservers.com ...
this eat up the processor? Is there a simple way of telling the code
to wait for a few ticks? Is there some way I can check the TcpClient


Search the docs before you ask. The function you want is called Sleep().
As to which class it's in, well you'll have to find out. Try the help
system, it's useful.

--
gabriel

Nov 15 '05 #8

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

Similar topics

9
1641
by: Oliver Douglas | last post by:
Mr. Jeff Relf drawled... > You dream of a world where everyone shares their source code , > sibling node to sibling node . > What if it's best the way things are , > With closed source code and parent nodes ? that's the way it's been from 1975, when m$oft was spawned, until 2000,
5
3851
by: bughunter | last post by:
Hi, Consider this code: ---- Monitor.Pulse(oLock); Monitor.Exit(oLock); ---- If a thread was waiting on oLock then will the current thread
3
37917
by: Ted | last post by:
In doing a db2 list applications show detail, I have 320 entries applications. Of those sometimes all of them are "UOW Waiting." Ususally there are from 1 to 4 marked UOW Executing. The rest are still waiting. What is meant by "waiting"? We have set TCPCOMMMGR to 4 (16 CPUs). We have increased IOCLEANERS and IOSERVERS, which had been set to low. Still the "waiting". Thanks in advance,
1
2871
by: Bartje | last post by:
Hey, I am wondering what the best solution will be to program the following problem in access, the dutch 97 edition. I am developing a database for a day care centre (for my girlfriend). This database consist out of six tables, Child, Employee, Group, ChildByGroup, EmployeeByGroup (it must be possible to place a child or an employee in more then 1 group) and GroupSort (this table gives some information about the different kind of...
3
12600
by: Elhurzen | last post by:
X-No-Archive: Yes >From what I understand, if multiple threads are waiting on a ManualResetEvent after calling WaitOne(), only one thread is guaranteed to be signaled when Set() is called on that ManualResetEvent. How do I ensure that _all_ waiting threads are signaled, without sacrificing any of the functionality or much of the simplicity of ManualResetEvent? Example: SignalingClass:
16
1962
by: Bruce Wood | last post by:
Maybe it's just late in my day, but I'm reading Jon's article on threading, in particular how to use Monitor.Wait() and Monitor.Pulse(), and there's something that's not sinking in. The code in question looks like this: public class ProducerConsumer { readonly object listLock = new object(); Queue queue = new Queue();
0
1684
by: wxqun | last post by:
I'm try tuning a SELECT statement which is used by a Cognos cube on a DB2 V7.2 +FP13. After I did the tuning, the "dynexpln" shows the "total cost" is down to 8214567 from 37345265, also I try to run the SQL in the cmd line, it now only took several minutes to return about 50M rows instead of +10 hours. The cube is re-built after the tuning, and I could see the same SQL running by "get snapshot for application.." , also the "list...
0
2193
by: wxqun | last post by:
I'm trying tuning a SELECT statement which is used by a Cognos cube on a DB2 V7.2 +FP13. After I did the tuning, the "dynexpln" shows the "total cost" is down to 8214567 from 37345265, also I try to run the SQL in the cmd line, it now only took several minutes to return about 50M rows instead of +10 hours. The cube is re-built after the tuning, and I could see the same SQL running by "get snapshot for application.." , also the "list...
4
3268
by: Jono | last post by:
Hi Everyone, As it says in the title, I'm looking for a way to display a page while long running operations are performed on the server. Ideally, I'd like some way to push the current request onto some stack, where it would continue to be processed asynchronously (most importantly preserving things like view state, form post data, etc). In the interim, while the main request is processed, a friendly page will be displayed to the user....
1
2777
by: Simon_21 | last post by:
Hi All, I have a servlet which is invoked from a jsp page. While the serlvet is executing, the jsp page is waiting for the servlet to complete. When the servlet completes, it informs the waiting jsp to redirect to another page. The waiting jsp has implemented onload which will redirect to the page informed by the servlet Server : (tomcat 6.0), Browser - IE 6.0, OS - WinXP
0
10264
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
10106
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
10039
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
8937
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
6717
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
5355
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
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
3
2852
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.