code: private static boolean waitForServerDown(int port, long timeout) {
      long start = System.currentTimeMillis();
      while (true) {
        try {
          Socket sock = new Socket("localhost", port);
          try {
            OutputStream outstream = sock.getOutputStream();
            outstream.write("stat".getBytes());
            outstream.flush();
          } finally {
            sock.close();
          }
        } catch (IOException e) {
          return true;
        }
  
        if (System.currentTimeMillis() > start + timeout) {
          break;
        }
        try {
          Thread.sleep(250);
        } catch (InterruptedException e) {
          // ignore
        }
      }
      return false;
    }
docs: XXX: From o.a.zk.t.ClientBase