docs: public synchronized int startServer(String ip, int port, boolean isDynamicPort) {
  
          if (isProxyRunning) {
              stopServer();
          }
  
          isProxyRunning = false;
  
          // ZAP: Set the name of the thread.
          thread = new Thread(this, threadName);
          thread.setDaemon(true);
          // the priority below should be higher than normal to allow fast accept on the server socket
          thread.setPriority(Thread.NORM_PRIORITY + 1);
  
          proxySocket = null;
          for (int i = 0; i < 20 && proxySocket == null; i++) {
              try {
                  proxySocket = createServerSocket(ip, port);
                  proxySocket.setSoTimeout(PORT_TIME_OUT);
                  isProxyRunning = true;
  
              } catch (UnknownHostException e) {
                  // ZAP: Warn the user if the host is unknown
                  if (View.isInitialised()) {
                      View.getSingleton().showWarningDialog(Constant.messages.getString("proxy.error.host.unknow") + " " + ip);
                  
                  } else {
                      System.out.println(Constant.messages.getString("proxy.error.host.unknow") + " " + ip);
                  }
                  
                  return -1;
              } catch (BindException e) {
                  String message = e.getMessage();
                  if (message == null || message.isEmpty()) {
                      handleUnknownException(e);
                      return -1;
                  }
  
                  if (message.startsWith("Cannot assign requested address")) {
                      showErrorMessage(Constant.messages.getString("proxy.error.address") + " " + ip);
                      return -1;
                  } else if (message.startsWith("Permission denied") || message.startsWith("Address already in use")) {
                      if (!isDynamicPort) {
                          showErrorMessage(Constant.messages.getString("proxy.error.port", ip, Integer.toString(port)));
                          return -1;
                      } else if (port < 65535) {
                          port++;
                      }
                  } else {
                      handleUnknownException(e);
                      return -1;
                  }
              } catch (IOException e) {
                  handleUnknownException(e);
                  return -1;
              }
  
          }
  
          if (proxySocket == null) {
              return -1;
          }
  
          thread.start();
  
          return proxySocket.getLocalPort();
  
      }