/**
   * Connect to Avatar.
   *
   * @throws IOException if the connection to Avatar could not be established
   */
  private void connect() throws IOException {
    // Do nothing if we are already connectd.
    if (socket != null) {
      return;
    }

    // Connect to Avatar
    if (host == null) {
      host = InetAddress.getLocalHost();
    }
    socket = new DatagramSocket();
    socket.connect(host, port);
    LOGGER.info("connected to Avatar at '" + host + ":" + port);
    feedback = new BMLFeedback(this, feedbackPort);
    feedback.start();
  }
  /**
   * Disconnects from Avatar.
   *
   * @throws IOException if the connection to Avatar could not be disconnected.
   */
  private void disconnect() throws IOException {
    // Do nothing if we are already disconnected
    if (socket == null) {
      return;
    }

    // disconnect.
    try {
      feedback.interrupt();
      feedback = null;
      socket.disconnect();
      socket.close();
    } finally {
      socket = null;
      feedback = null;
    }
    LOGGER.info("diconnected from Avatar");
  }