title: TCP Client sending but not receiving and Server receiving but not sending
body: <p>I have made a program in Java that allows the server admin to monitor the client processes. It's all OK when I'm sending data to the server. But, when I try to send data back, it just doesn't receive it.</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  class TCPServer {
  public static void main(String argv[]) throws Exception {
      String clientSentence;
      String capitalizedSentence;
      ServerSocket welcomeSocket = new ServerSocket(6789);
      while (true) {
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();
          System.out.println("Received: " + clientSentence);
          capitalizedSentence = clientSentence.toUpperCase();
          outToClient.writeBytes(capitalizedSentence);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I found out the error, i was not sending an "\n" after the message, causing a pile-up and that never got sent.</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  class TCPServer {
  public static void main(String argv[]) throws Exception {
      String clientSentence;
      String capitalizedSentence;
      ServerSocket welcomeSocket = new ServerSocket(6789);
      while (true) {
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
          clientSentence = inFromClient.readLine();
          System.out.println("Received: " + clientSentence);
          capitalizedSentence = clientSentence.toUpperCase() + "\n"; // &lt;-----
          outToClient.writeBytes(capitalizedSentence);
      }
  }
  </code></pre>
  
  <p>}</p>