title: Socket client not receiving messages from server only when server performs a loop
body: <p>I am trying to make a server (written in Python) and a client (written in Java) to communicate. The server code is the following:</p>
  
  <pre><code>import socket               # Import socket module
  connection=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  connection.bind(('',12800))
  connection.listen(5)
  
  connection_with_client, info_connection = connection.accept()
  
  msg=b""
  while(msg!=b"stop"):
      print("Entering loop")
      msg = connection_with_client.recv(1024)
      connection_with_client.send(b"This is a message")
      print("Sent")
  
  connection_with_client.close()
  connection.close()
  </code></pre>
  
  <p>The client code is:</p>
  
  <pre><code>try {
          socket = new Socket(InetAddress.getLocalHost(),12800); 
  
          PrintWriter out = new PrintWriter(socket.getOutputStream());
          out.print("stop");
          out.flush();
          System.out.println("Sent");
          in = new BufferedReader (new InputStreamReader (socket.getInputStream()));
          String message_from_server = in.readLine();
          System.out.println("Received message : " + message_from_server);
          socket.close();
          } catch (UnknownHostException e) {
              e.printStackTrace();
          } catch (IOException e) {               
              e.printStackTrace();
      }
  </code></pre>
  
  <p>The strange thing is: when the client sends the message "stop", everything goes fine, message from server is received by the client. Now, when the client sends another message than "stop", the server tells it has sent the message, and enters the loop a second time, however the client never receives the message and gets stuck at the in.readLine() instruction. </p>
  
  <p>I really don't get why as the first passage in the loop should have the same effects in both situations... Any help welcome!</p>