title: TCP server sending and receiving data multiple clients with multithreading
body: <p>I want to design a TCP server which listens for x clients. X is small, say around 10 and its fixed. Clients may connect at any time. Once the connection is established (<code>accept()</code> successful) I spawn a thread for each client and handle them.</p>
  
  <p>In this <code>handle()</code> function I want to send commands to client and receive the data accordingly.</p>
  
  <p><strong>Problem:</strong> 
  Once a command has been sent from the server the client responds by sending data continuously. How do I send a command back to the client to stop it? As with the current code I'm in a loop receiving data from the client. </p>
  
  <ol>
  <li>I don't know how to send the command from server thread while receive is in progress, like should I need to have another thread (to send cmds) once the connection is established? </li>
  <li>How to continuously receive data from clients and also send commands at the same time? Sending commands to each client based on user inputs. (Say user wants client1 to start sending data, then I have to send START to client1. And user wants to stop the client1 from sending, so I need to send STOP to client1 And if user wants data3 cmd to be sent to client 4 then send command DATA3 to client4  etc. How do identify the client in this case? Basically forming a small protocol**</li>
  </ol>
  
  <p>The below code is working where I can listen on socket and client connects and sends data. I'm not sure of how to send user inputted commands to the right client (say client4) and also receive at same time.</p>