title: DataOutputStream- Always writing to server?
body: <p>For the purposes of a simple 2D game, I need my client program to always be sending coordinates to a server. </p>
  
  <p>So, I created a test to see if I could make both players have the same velocity by sending and retrieving values from the server.</p>
  
  <pre><code>package main;
  
  import java.io.DataInputStream;
  import java.io.DataOutputStream;
  import java.io.IOException;
  
  public class DataSender implements Runnable{
  
      private DataInputStream fromServer;
      private DataOutputStream toServer; 
  
      Player player;
      Player opponent;
  
      public DataSender(DataInputStream fromServer, DataOutputStream toServer, Player player, Player opponent){
  
          this.fromServer = fromServer;
          this.toServer = toServer; 
  
          this.player = player;
          this.opponent = opponent;   
      }
  
      @Override
      public void run() {
  
          while(true){
  
                  try {
                      toServer.writeInt(player.velX);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
                  try {
                      opponent.velX = fromServer.readInt();
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
          }   
      }
  }
  </code></pre>
  
  <p>The <code>while(true)</code> loop only executes one time upon thread creation. How can I establish a constant stream of data?</p>