code: private static void waitForStop(TestContainer testContainer, int localPort) {
          try {
              ServerSocket serverSocket = new ServerSocket(localPort);
              Socket socket = serverSocket.accept();
  
              InputStreamReader isr = new InputStreamReader(socket.getInputStream(), "UTF-8");
              BufferedReader reader = new BufferedReader(isr);
              OutputStream os = socket.getOutputStream();
              OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
              PrintWriter pw = new PrintWriter(writer, true);
              boolean running = true;
              while (running) {
                  String command = reader.readLine();
                  LOG.debug("command = {}", command);
                  if (command.equals("stop")) {
                      testContainer.stop();
                      pw.println("stopped");
                      writer.flush();
                      LOG.info("test container stopped");
                  }
                  else if (command.equals("quit")) {
                      LOG.debug("quitting PaxExamRuntime");
                      pw.close();
                      socket.close();
                      serverSocket.close();
                      running = false;
                  }
              }
          }
          catch (IOException exc) {
              LOG.debug("socket error", exc);
          }
      }
docs: Opens a server socket listening for text commands on the given port.
  Each command is terminated by a newline. The server expects a "stop" command
  followed by a "quit" command.
  
  @param testContainer
  @param localPort