title: How can I accept multiple clients to a TCP server?
body: <p>I currently have a TCP server set up that can accept a connection from a client and echo whatever the client inputs. How would I go about making multiple clients connect to the server and have their input sent to all clients? </p>
  
  <p>It appears I should fork, but I'm not fully sure how...</p>
  
  <p>On the server, should I place an infinite loop starting from accept (or listen?) that will fork when there is a new connection? Then on the child process I would have to close the socket from a previous process and connect to the new one, but once again I'm not fully sure.  </p>
  
  <p>What would the pseudo code look like in regards to just the forks and socket manipulation? My guess:</p>
  
  <pre><code>while(1) //before connection or accept?
  
  pid = fork()
  
  if(pid==0)
    // open socket from client
    // run the rest of the code 
    // end process when client disconnects
  else
    // close socket from client
  </code></pre>