473,394 Members | 1,951 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,394 software developers and data experts.

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 1995
> 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*******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.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*******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.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.Threading.Thread.Sleep( ... );
"Burns" <an*******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.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*******@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.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.WriteLine("some command");
streamWriter.Flush();

string response = streamReader.ReadLine();

(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*******@discussions.microsoft.com> a écrit dans le message de
news:85**********************************@microsof t.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.meganewss ervers.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
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...
5
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
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...
1
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...
3
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...
16
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...
0
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...
0
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...
4
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...
1
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.