title: Java help creating a new socket per connected user
body: <p>I am creating a chat server and i can not get more than one connection established, i believe that this is due to there being only one socket. I have read that a thread is capable of handling more than one socket connection at a time but each client must have it's own socket. like a wall outlet. There must be 1 outlet per plug. How do i create a socket for each client to use to communicate to the server? I will supply a bit of code to help you guys base your help off of. Here is where the single socket (connection) is accepted.</p>
  
  <pre><code> private void waitForConnection() throws IOException
   {
       connection = server.accept();
       showMessage("\nNow connected to " + connection.getInetAddress().toString());
       clientCount += 1;
   }
  </code></pre>
  
  <p>Here is where the code is called from at server start:</p>
  
  <pre><code>public void startRunning()
  {
    try
    {
       server = new ServerSocket(1337, 10);
       while(true)
       {
          try
          {
              showMessage("Waiting For a Player To Connect...");
              waitForConnection();
              setupStreams();
              whileChatting();
  
          }
          catch(EOFException eofException)
          {
             showMessage("\n Server ended the connection! ");
          }
          finally
          {
             closeConnections();
          }
       }
    }
    catch(IOException ioException)
    {
       ioException.printStackTrace();
    }
  }
  </code></pre>
  
  <p>Now this code works perfectly for the first connected client. All others simply cant connect. Thanks in advance to all who have submitted an answer.</p>