Advertisement

.NET version of select()?

Started by November 21, 2005 03:55 PM
0 comments, last by Arild Fines 19 years, 3 months ago
I'm using C# to write a server that can host several clients. I'm using TcpClient right now (which gives public access to its internal Socket class). The problem is that I can't figure out how to do a select() type statement on them with a timeout. Basically, I'm doing a loop like this:

while(true)
{
foreach(TcpClient c in m_Clients)
  if(c.NetworkStream.DataAvailable)
    Process(c);
Sleep(5);
}
It ain't pretty. Is there a better way to do this? ~BenDilts( void );
The Socket class has a static Select() method. Does that work for you? (I've never played much with TcpClient).

However, Select() isn't the best way to deal with sockets in .NET. Read this article for a better solution.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement