def next_port
      port = @next_port
      @next_port -= 1
      @next_port = MAX_PORT if @next_port < MIN_PORT
      # check if the port is in use, if so get the next_port
      begin
        TCPSocket.new '127.0.0.1', port
      rescue Errno::EADDRINUSE
        next_port()
      rescue Errno::ECONNREFUSED
        port
      else
        next_port()
      end
    end
def next_port
      port = @next_port
      @next_port -= 1
      @next_port = MAX_PORT if @next_port < MIN_PORT
      # check if the port is in use, if so get the next_port
      begin
        TCPSocket.new '127.0.0.1', port
      rescue Errno::EADDRINUSE
        next_port()
      rescue Errno::ECONNREFUSED
        port
      else
        next_port()
      end
    end
Grabs the next available port number and returns it.