// returns port number
static int installHelloMessage(final S helloString) ctex {
  final ServerSocket serverSocket = new ServerSocket(0);
  int port = serverSocket.getLocalPort();
  
  //serverSocket.setSoTimeout(1000);
  
  daemon { // todo: higher priority
    while (true) {
      try {
        final Socket s = serverSocket.accept();
        print("connect");
        thread {
          try {
            Writer w = new OutputStreamWriter(s.getOutputStream(), "UTF-8");
            w.write(helloString + "\n");
            w.flush();

            final BufferedReader in = new BufferedReader(
                new InputStreamReader(s.getInputStream(), "UTF-8"));
                
            while (true) {
              String line = in.readLine();
              if (line == null) break;
              print("> incoming: " + line);
              if (line == "kill" || line == "kill!")
                if (io.isLocalConnection())
                  killMyself();
                else
                  print("Ignoring kill command from non-local: " + io.getSocket().getInetAddress());
            }
          } finally {
            print("disconnect");
          }
        }
      } catch (SocketTimeoutException e) {
      }
    }
  }
  
  return port;
}