title: libGDX client (server) client connection
body: <p>I am trying to create a multiplayer game.
  I think there are three possible ways to do this:</p>
  
  <pre><code>1. Port Forwarding
  </code></pre>
  
  <p>Only a few people will open a port on their router.</p>
  
  <pre><code>2. UDP / TCP hole punching
  </code></pre>
  
  <p>This is verry ccomplicated and will not work with every router / NAT.</p>
  
  <pre><code>3. Relay Server
  </code></pre>
  
  <p>I think this is the easiest method to accomplish a multiplayer.
  So my plan is to establish a socket connection to a PHP server which will also have a socket connection with the other player and passes the data.</p>
  
  <p>At the time I have a client part and a test server part in Java:</p>
  
  <pre><code>SocketHints hints = new SocketHints();
  Socket client = Gdx.net.newClientSocket(Net.Protocol.TCP, textfield.getText(), 9021, hints);
         try {
                 client.getOutputStream().write((textfield2.getText() + "\n").getBytes());
             } catch (IOException e) {
                  e.printStackTrace();
             }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>new Thread(new Runnable() {
          @Override
          public void run() {
              ServerSocketHints serverSocketHint = new ServerSocketHints();
              serverSocketHint.acceptTimeout = 0;
              ServerSocket serverSocket = Gdx.net.newServerSocket(Net.Protocol.TCP, 9021, serverSocketHint);
              while (true) {
                  Socket socket = serverSocket.accept(null);
                  BufferedReader buffer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                  try {
                      status += "Receiving message: \"" + buffer.readLine() + "\"\n\n";
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }).start();
  </code></pre>
  
  <p>How can I receive data from the socket connection from the client?</p>
  
  <p>And is there maybe a better way to do this?</p>