View Single Post
Old Dec 3rd, 2005, 9:22 PM   #7
Animatronic
Programmer
 
Join Date: Jun 2005
Posts: 99
Rep Power: 4 Animatronic is on a distinguished road
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
				}
			}
		}
	}
Animatronic is offline   Reply With Quote