Question about TcpListener and TcpClient

Question about TcpListener and TcpClient

Post by V29uIFdvb » Tue, 11 Oct 2005 13:55:04


I am writing a simple chat program in C# using TcpListener and TcpClient
class. In VB6, Winsock will rise an event when data arrives, but apparently
TcpListener does not have that. So how can I know when data arrives?

One solution I could think of is using Thread to continuously checking
whether there is data arrived or not. Is there a better way to accomplish
this?

Thank you in advance

Won
 
 
 

Question about TcpListener and TcpClient

Post by William St » Wed, 12 Oct 2005 00:16:13

Actually, pooling on DataAvailable is not a good idea. Most of the time it
will be 0 if done in a tight loop and that is fantasic waste of cpu. There
are many other options such as using blocking reads, Select(), or async
reads.

--
William Stacey [MVP]

 
 
 

Question about TcpListener and TcpClient

Post by Abubaka » Wed, 12 Oct 2005 03:58:51

I think you could check the DataAvailable property of NetworkStream inside
an infinite loop. If u want to give a delay to listening to reduce cpu
comsumption you could do a Thread.Sleep(your delay figure here).

Ab.
http://www.yqcomputer.com/




apparently
 
 
 

Question about TcpListener and TcpClient

Post by V29uIFdvb » Wed, 12 Oct 2005 17:38:03

Thanks for the answers.

But can you give m some examples or links about blocking reads, Select(), or
async reads.

Thanks again for the help

Won Won