code: @SuppressWarnings("deprecation")
      void closeListener() {
          if (listener != null && listener.isListening()) {
              listener.stop();
  
              // Wait until the listener says it has stopped, but don't wait forever
              int count = 0;
              while (listenerThread != null && listenerThread.isAlive() && count < 50) {
                  ModbusUtil.sleep(100);
                  count++;
              }
              // If the listener is still not stopped, kill the thread
              if (listenerThread != null && listenerThread.isAlive()) {
                  listenerThread.stop();
              }
              listenerThread = null;
          }
          isRunning = false;
      }
docs: Closes the listener of this slave