@Override
    public void run() {
        try {
            waitForConnection();
            shutDownServer();
            while(true) {
                synchronized (this) {
                    if(dis.available() != 0) {
                        throw new UnexpectedCommunicationBehaviorException("I did not expect any message from client");
                    }
                    if(discoveredDevices.isEmpty())
                        this.wait(5000);
                    else {
                        DebugPrint.print("sending device information");
                        dos.writeInt(NEXT_DISCOVERED_DEVICE);
                        DebugPrint.print("send flag");
                        discoveredDevices.pop().transmitYourself(dos);
                    }
                    if(isStopped)
                        break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            handler.notifyUnhandledException(e);
        } catch (InterruptedException e) {
            e.printStackTrace();
            handler.notifyUnhandledException(e);
        } catch (UnexpectedCommunicationBehaviorException e) {
            e.printStackTrace();
            handler.notifyUnhandledException(e);
        }
    }