title: Wait for client to enter name before broadcasting the server message
body: <p>From GameServer.java:</p>
  <pre class="lang-java prettyprint-override"><code> while (true) {
              Socket clientSocket = serverSocket.accept();
              PlayerThread playerThread = new PlayerThread(clientSocket, this);
              playerThreads.add(playerThread);
              playerThread.start();
              if (playerThreads.size() == maxPlayers) {
                  broadcast(&quot;All players have joined! Let the game begin!&quot;, null);
              }
          }
  </code></pre>
  <p>From PlayerThread.java:</p>
  <pre class="lang-java prettyprint-override"><code> @Override
      public void run() {
          try {
              BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
              out = new PrintWriter(socket.getOutputStream(), true);
              out.println(&quot;What's your name? &quot;);
              String userName = in.readLine();
              Player player = new Player(userName);
              gameServer.addPlayer(p);
              String clientMove;
              while ((clientMove = in.readLine()) != null) {
                  gameServer.makeMove(player, clientMove);
                  gameServer.broadcast(p.getName() + &quot; made the move:  &quot; + clientMove, this);
              }
  
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  <p>Starting the server:</p>
  <p><a href="https://i.stack.imgur.com/7EcK9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7EcK9.png" alt="enter image description here" /></a></p>
  <p>Client1 at the end:</p>
  <p><a href="https://i.stack.imgur.com/SimFL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SimFL.png" alt="enter image description here" /></a></p>
  <p>Client2 at the end:</p>
  <p><a href="https://i.stack.imgur.com/0iq08.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0iq08.png" alt="enter image description here" /></a></p>
  <p>How do I wait for the last client (here, client2) to enter their name before broadcasting the message?</p>
  <p>Here's the broadcast function:</p>
  <pre class="lang-java prettyprint-override"><code>public void broadcast(String message, PlayerThread excluded) {
          for (PlayerThread p : playerThreads) {
              if (p != excluded)
                  p.sendMessage(message);
          }
      }
  </code></pre>