Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-30168

Pick random port to start webserver

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • vncviewer-plugin
    • None

      In the source code there is for loop to pick up the right port this leads to various outputs in the console trying to start a webserver.

      It would be a better option to add function to retrieve a random open port for this.

      Something like:

      public static int findFreePort() {
      ServerSocket socket= null;
      try

      { socket= new ServerSocket(0); return socket.getLocalPort(); }

      catch (IOException e) {
      } finally {
      if (socket != null) {
      try

      { socket.close(); }

      catch (IOException e) {
      }
      }
      }
      return -1;
      }
      (this function template is taken from org.eclipse.jdt.launching.SocketUtil)

      Best regards,
      Falk

            tbaum Dimitri Tenenbaum
            zilmtt Falk Zilm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: