title: TCP connection - server only sends message after closing socket
body: <p>I am trying to make a client send a request to a server and receive a response whilst keeping to connection up.</p>
  
  <p><strong>If i close the socket:</strong></p>
  
  <pre><code>//server side
  outToClient.writeBytes("Message to send");
  connectionSocket.close();
  
  //client side
  serverResponse = inFromServer.readLine(); 
  System.out.println("FROM SERVER: " + serverResponse);
  </code></pre>
  
  <p>Output on client side</p>
  
  <blockquote>
    <p>FROM SERVER: Message to send</p>
  </blockquote>
  
  <p>And after that the connection is lost, obviously.</p>
  
  <p><strong>If i do not close the socket:</strong></p>
  
  <pre><code>//server side
  outToClient.writeBytes("Message to send");
  
  //client side
  serverResponse = inFromServer.readLine(); 
  System.out.println("FROM SERVER: " + serverResponse);
  </code></pre>
  
  <p>No output on client side.
  The server never sends the message or the client never receives it.</p>
  
  <p>Anyone knows a possible reason for this to be happening?
  The client uses a thread to receive messages and a thread to send messages. The client socket is created in the main client thread so receiver and sender threads use the current socket to communicate.</p>
  
  <p>Thanks in advance.</p>