I'm working on my first maultiplayer game in java. But I have a problem. Only the latest connected socket get any data, and I have no idea why. I tried to make a loop that would send the collected data to all the players but only the newest one gets it.
Here is my code
public void run() { while(true) { String data = ""; for(Player player : Player.getPlayers()) { player.move(); data += player.getData(); } data += "done"+in.newline; for(Player player : Player.getPlayers()) { Socket socket = player.getSocket(); if(!socket.isClosed()) { try { OutputStream out = socket.getOutputStream(); out.write(data.getBytes()); out.flush(); } catch (IOException e) { e.printStackTrace(); } } } try{Thread.sleep(10);}catch(Exception e){} } }