@Override
    public void run() {
        try {
            while (true) {
                synchronized (this) {
                    if(dis.available() != 0) {
                        int command = dis.readInt();
                        if(command == TransferDeviceInformation.NEXT_DISCOVERED_DEVICE) {
                            DebugPrint.print("reveicing device information");
                            handler.addDiscoveredDevice(DiscoveredBluetoothDevice.receiveDeviceInformation(dis));
                        } else {
                            throw new UnexpectedCommunicationBehaviorException("expected NEXT_DISCOVERED_DEVICE flag but got different " + command);
                        }
                        if(isStopped)
                            break;
                    } else {
                        this.wait(5000);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            handler.notifyUnhandledException(e);
        } catch (UnexpectedCommunicationBehaviorException e) {
            e.printStackTrace();
            handler.notifyUnhandledException(e);
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
            handler.notifyUnhandledException(e);
        } finally {
            handler.notifyStop(this);
        }
    }