title: Client/Server chat, sending online user list, only received by the most recently connect client?
body: <pre><code>static ArrayList&lt;Client&gt; clients = new ArrayList&lt;Client&gt;();    
  while (true)
              {                                              
                  Socket s = server.accept();
                  System.out.println("Client connected from " + s.getLocalAddress().getHostName());  
  
                  Thread t = new Thread(new Client(s));
                  t.start();                   
  
              }
  </code></pre>
  
  <p>Simply premise, inside the Client class that just got made i am adding to a static ArrayList of 'Client' located in the main server class (above) i.e. </p>
  
  <pre><code>clients.add(Client.this);
  </code></pre>
  
  <p>I am then simply every 10 seconds, sending the currently online users as an object to all the clients currently in the ArrayList (Global message in effect)</p>
  
  <pre><code> for(int i =0; i &lt; clients.size(); i++)
                     {
                         System.out.print("sending list");
                         clients.get(i).sendList();
                     }
  </code></pre>
  
  <p>Now, it DOES correctly add the right number of clients etc.. and the list is gathered correctly, the client happily recieves this list every 10 seconds, UNTIL, another client connects to the server, as soon as this happens, the first client stops receiving the list and the new one takes it's place, getting all the 'received list' notifications. Whats going on here?</p>
  
  <p>EDIT: sendList() code</p>
  
  <pre><code>public void sendList()
          {
              try 
              {
                  ChatListObject list = new ChatListObject();
                  list.setList(helper.getOnlineUsers());
                  out.writeObject(list);
                  out.flush();
              } 
              catch (IOException iOException) 
              {
                  System.out.println(iOException);
              }
          }
  </code></pre>
  
  <p>Things tried for adding client:</p>
  
  <pre><code>                Client client = new Client(s);              
                  Thread t = new Thread(client);
                  t.start();                       
                  clients.add(client);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>clients.add(this);
  </code></pre>
  
  <p>in the client itself</p>