title: Java Thread Sockets (PrintWriter & BufferedReader)
body: <p>I'm trying to create a game using only two classes - ServerSocket and Socket. Everything must be at the TCP (not UDP), while architecture is necessarily P2P. The way this game works is that one player chooses a number, then the other and it starts with one of them (no matter which one) counting down. I came across a problem. I establish a connection between two clients and both may enter the selected number. I do not know why I can not send this number to another client. Is the problem that Socket can not send and receive messages at the same time? I've read that there is a possibility to do this using two separate Threads (one receives data, the other sends), but I do not know how exactly.</p>
  
  <pre><code>@Override
  public void run() {
      BufferedReader br = new BufferedReader(new InputStreamReader(System. in ));
      PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
  
      System.out.println("PICK A NUMBER:");
      while (!br.ready()) {
          Thread.sleep(500);
      }
      Integer numberGamePicked = Integer.parseInt(br.readLine());
      Thread.sleep(500);
      out.println(numberGamePicked);
      Thread.sleep(1000);
  
      BufferedReader in =new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
      int whatOpponentSend = Integer.parseInt( in .readLine());
      System.out.println("RECEIVED " + whatOpponentSend);
  }
  </code></pre>
  
  <p>Of course, up to this point everything is in the run() method. Is the problem that both of them execute the same code at the same time?</p>