using System.Net;
using System.Net.Sockets;
using System.Collections;
...
Bool bRunning = true;
ArrayList socklist = new ArrayList();
ArrayList socklistcopy;
Socket sockserv = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sockserv.Bind(new IPEndPoint(IPAddress.Any, 4001));
sockserv.Listen(10);
socklist.Add(sockserv);
while(bRunning)
{
socklistcopy = new ArrayList(socklist);
Socket.Select(socklistcopy, null, null, 1);
foreach(Socket cursock in socklistcopy)
{
if(cursock == sockserv)
{
socklist.Add( sockserv.Accept() );
}
else
{
byte [] buffer = new byte[1024];
int recvbytes = cursock.Recieve(buffer);
if(recvbytes <= 0)
{
cursock.Close();
socklist.Remove(cursock);
}
else
{
//Do your stuff with the recieved data
}
}
}
}
...