I have been trying to send a simple string between a Java client socket and a Python server socket. This is the code for the server socket:

```
HOST=''
PORT=12000
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADRR,1)
s.bind((HOST,PORT))
s.listen(5)
device=variador()
while True:

  conn,addr=s.accept()
  if data=="turn_on":
     respuesta=device.send_order(variador.start_order)
     conn.send(respuesta+'\n')
     conn.close()

```

and the client code is:

```
   try {

            Socket socket = new Socket("192.168.10.171", 12000);

            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            BufferedReader in = new BufferedReader(new InputStreamReader(
                                       socket.getInputStream()));    

            BufferedReader stdIn = new BufferedReader(
                                          new InputStreamReader(System.in));

            out.print(command);

            out.close();
            in.close();
            socket.close();

        } catch (UnknownHostException e) {
            System.err.println("Unknown Host.");
           // System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for "
                               + "the connection.");
          //  System.exit(1);
        }

```

Everything works fine until I try to read the server's response, using this:

```
    String userInput;
  while ((userInput = stdIn.readLine()) != null) {
  out.println(userInput);
  System.out.println("echo: " + in.readLine());
  }

```

then the code hangs and the Python server does not receive any information, which I tested using print.

Is there a problem trying to send first and then wait for a response from the server in the Java client?

Any help will be much appreciated.