Excuse the horrible pseudo code, but this is how I would lay out a multiple client server (with non-blocking sockets):
while( true )
{
if( ListenSocket.Listen() != error ) // accept new clients
{
ClientList.Add( ListenSocket.Accept() );
}
for each( Socket s in ClientList )
{
int recvValue;
if( (recvValue = s.Recv( data )) > 0 )
{
//process command
}
else
{
if( recvValue == 0 ) //client has quit
{
s.Close();
ClientList.Remove( s );
}
else
{
// process error
}
}
}
}