/** This is the body of the listening thread */
  public void run() {
    SocketAddress sender;

    checkBuffer();

    try {
      listen:
      while (isListening) {
        try {
          byteBuf.clear();

          // temporary until we work out a better way...
          // Fixed buffer size limits the maximum size of received packets
          // Seems there are always limitations and a default going back to the constant
          // DEFAULTBUFSIZE
          byte[] buffer = new byte[getBufferSize()];
          DatagramPacket dp = new DatagramPacket(buffer, buffer.length);

          ms.receive(dp);
          byteBuf.put(buffer);
          sender = dp.getSocketAddress();

          if (!isListening) break listen;
          if ((target != null)) continue listen;

          flipDecodeDispatch(sender);
        } catch (ClosedChannelException e1) { // bye bye, we have to quit
          if (isListening) {
            //							System.err.println( e1 );
            System.err.println(
                "OSCReceiver.run : " + e1.getClass().getName() + " : " + e1.getLocalizedMessage());
          }
          return;
        } catch (IOException e1) {
          if (isListening) {
            System.err.println(
                "OSCReceiver.run : " + e1.getClass().getName() + " : " + e1.getLocalizedMessage());
            //							System.err.println( new OSCException( OSCException.RECEIVE, e1.toString() ));
          }
        }
      } // while( isListening )
    } finally {
      synchronized (threadSync) {
        thread = null;
        threadSync.notifyAll(); // stopListening() might be waiting
      }
    }
  }