/** Reads messages */
  public void run() {
    while (!terminateThread) {
      for (int i = 0; i < socketStructureManagement.getSocketStructureCount(); i++) {
        BinaryDeviceHostAddressSocketStructure currentSocketStructure =
            (BinaryDeviceHostAddressSocketStructure)
                socketStructureManagement.getSocketStructure(i);

        BinaryMessageObject message = null;
        // read search messages
        do {
          message =
              SocketHelper.readBinaryMessage(null, currentSocketStructure.getDiscoverySocket(), 10);
          if (message != null) {
            // Portable.println("Discovery: Received multicast discovery message");
            binaryDevice.processDiscoveryMessage(message, currentSocketStructure);
          }
        } while (message != null);
        // read search reply messages
        do {
          message =
              SocketHelper.readBinaryMessage(
                  null, currentSocketStructure.getDescriptionSocket(), 10);
          if (message != null) {
            Portable.println(
                "Description: Received description request from "
                    + IPHelper.toString(message.getSourceAddress())
                    + " with "
                    + BinaryUPnPConstants.toDebugString(message.getBody()));
            binaryDevice.processDescriptionMessage(message, currentSocketStructure);
          }
        } while (message != null);
        do {
          // read control messages
          message =
              SocketHelper.readBinaryMessage(null, currentSocketStructure.getControlSocket(), 10);
          if (message != null) {
            binaryDevice.processControlMessage(message, currentSocketStructure);
          }
        } while (message != null);
      }
      ThreadHelper.sleep(50);
    }
    terminated = true;
  }
 /**
  * Retrieves the ssdpMulticastSocketAddress.
  *
  * @return The ssdpMulticastSocketAddress.
  */
 public String getSSDPMulticastSocketAddressString() {
   return IPHelper.toString(ssdpMulticastSocketAddress);
 }
 /**
  * Returns friendly name plus discovery address
  *
  * @return A string like <Device name> at <device address>
  */
 public String toDiscoveryString() {
   return friendlyName + " at " + IPHelper.toString(getDeviceDescriptionSocketAddress());
 }