title: Best way to accept multiple tcp clients?
body: <p>I have a client/server infrastructure. At present they use a TcpClient and TcpListener to send a receive data between all the clients and server. </p>
  
  <p>What I currently do is when data is received (on it's own thread), it is put in a queue for another thread to process in order to free the socket so it is ready and open to receive new data.</p>
  
  <pre><code>                // Enter the listening loop.
                  while (true)
                  {
                      Debug.WriteLine("Waiting for a connection... ");
  
                      // Perform a blocking call to accept requests.
                      using (client = server.AcceptTcpClient())
                      {
                          data = new List&lt;byte&gt;();
  
                          // Get a stream object for reading and writing
                          using (NetworkStream stream = client.GetStream())
                          {
                              // Loop to receive all the data sent by the client.
                              int length;
  
                              while ((length = stream.Read(bytes, 0, bytes.Length)) != 0)
                              {
                                  var copy = new byte[length];
                                  Array.Copy(bytes, 0, copy, 0, length);
                                  data.AddRange(copy);
                              }
                          }
                      }
  
                      receivedQueue.Add(data);
                  }
  </code></pre>
  
  <p>However I wanted to find out if there is a better way to do this. For example if there are 10 clients and they all want to send data to the server at the same time, one will get through while all the others will fail.Or if one client has a slow connection and hogs the socket all other communication will halt. </p>
  
  <p>Is there not some way to be able to receive data from all clients at the same time and add the received data in the queue for processing when it has finished downloading? </p>