public void run() {
    Thread thisThread = Thread.currentThread();

    ControlPoint ctrlPoint = getControlPoint();

    while (deviceNotifyThread == thisThread) {
      Thread.yield();

      // Thanks for Kazuyuki Shudo (08/23/07)
      SSDPPacket packet = null;
      try {
        packet = receive();
      } catch (IOException e) {
        break;
      }

      // Thanks for Mikael Hakman (04/20/05)
      if (packet == null) continue;

      // Thanks for Inma (02/20/04)
      InetAddress maddr = getMulticastInetAddress();
      InetAddress pmaddr = packet.getHostInetAddress();
      if (maddr.equals(pmaddr) == false) {
        Debug.warning("Invalidate Multicast Recieved from IP " + maddr + " on " + pmaddr);
        continue;
      }
      // TODO Must be performed on a different Thread in order to prevent UDP packet losses.
      if (ctrlPoint != null) ctrlPoint.notifyReceived(packet);
    }
  }
Пример #2
0
 public void run() {
   Thread thread = Thread.currentThread();
   ControlPoint controlpoint = getControlPoint();
   do {
     SSDPPacket ssdppacket;
     do {
       if (deviceNotifyThread != thread) {
         return;
       }
       Thread.yield();
       InetAddress inetaddress;
       InetAddress inetaddress1;
       try {
         ssdppacket = receive();
       } catch (IOException ioexception) {
         return;
       }
     } while (ssdppacket == null);
     inetaddress = getMulticastInetAddress();
     inetaddress1 = ssdppacket.getHostInetAddress();
     if (!inetaddress.equals(inetaddress1)) {
       Debug.warning(
           (new StringBuilder("Invalidate Multicast Recieved from IP "))
               .append(inetaddress)
               .append(" on ")
               .append(inetaddress1)
               .toString());
     } else if (controlpoint != null) {
       controlpoint.notifyReceived(ssdppacket);
     }
   } while (true);
 }
 public SSDPPacket receive() {
   byte ssdvRecvBuf[] = new byte[SSDP.RECV_MESSAGE_BUFSIZE];
   SSDPPacket recvPacket = new SSDPPacket(ssdvRecvBuf, ssdvRecvBuf.length);
   recvPacket.setLocalAddress(getLocalAddress());
   try {
     ssdpMultiSock.receive(recvPacket.getDatagramPacket());
     recvPacket.setTimeStamp(System.currentTimeMillis());
   } catch (Exception e) {
     // Debug.warning(e);
   }
   return recvPacket;
 }