// assumes hello message has not been read yet
static DialogIO replaceHelloMessage(final DialogIO io, final S newMsg) {
  io.readLine(); // read old hello msg
  ret new DialogIO() {
    bool sent;
    
    // delegate all but readLineImpl()
    boolean isStillConnected() { ret io.isStillConnected(); }
    boolean isLocalConnection() { ret io.isLocalConnection(); }
    Socket getSocket() { ret io.getSocket(); }
    public void close() ctex { io.close(); }
    void sendLine(String line) { io.sendLine(line); }
    
    String readLineImpl() {
      if (!sent) {
        sent = true;
        ret newMsg;
      }
      ret io.readLine();
    }
  };
}