0

Good day all, Please I have this code below for testing download speed, and has been working for some time now. But recently always bring this error and doesn't work any more. Please help look into it.

Thanks

Tried with this url: 'https://drive.google.com/open?id=1MBHJXeRxMLLwHFpqbgTdEPsFArMM0cz7'

[Error: Unable to resolve host "drive.google.com": No address associated with hostname]

Tried with this url: 'https://upload.wikimedia.org/wikipedia/commons/b/b9/Pizigani_1367_Chart_1MB.jpg'

[Error: Unable to resolve host "upload.wikimedia.org": No address associated with hostname]

const downloadSizeInBits = 12000000;
const metric = 'MBps';
export const measureConnectionSpeed = (imageURIParam: string): any => {
   const imageURI = imageURIParam
   ? imageURIParam
   : 'https://drive.google.com/open?id=1MBHJXeRxMLLwHFpqbgTdEPsFArMM0cz7';

   return new Promise((resolve, reject) => {
     const startTime = new Date().getTime();
     RNFetchBlob.config({
       fileCache: false,
     })
     .fetch('GET', imageURI, {})
     .then((res) => {
        const endTime = new Date().getTime();
        const duration = (endTime - startTime) / 1000;
        const speed = downloadSizeInBits / (1024 * 1024 * duration);

        resolve({metric, speed});
     })
     .catch(reject);
   });
  };

  //Called from here in another component

  getDownloadSpeed = async () => {
     try {
        const networkSpeed = await measureConnectionSpeed();
        this.setState({value: networkSpeed.speed});
        return networkSpeed.speed;
     } catch (error) {
       //handle error
       ToastAndroid.show(
          'Network Issues, unable to get download speed',
           ToastAndroid.LONG,
       );
       console.log(error);
     }
   };

Thanks

Tim

Timothy Ayodele
  • 185
  • 1
  • 1
  • 9
  • This is similar to your question: https://stackoverflow.com/questions/6355498/unable-to-resolve-host-url-here-no-address-associated-with-hostname – Jagjeet Singh Jan 15 '21 at 12:55
  • Yes @JagjeeSingh, I mentioned that I will open another question for it, I didn't want it clogged up with the other question. – Timothy Ayodele Jan 15 '21 at 12:59
  • Based on the answer given here: https://stackoverflow.com/questions/6355498/unable-to-resolve-host-url-here-no-address-associated-with-hostname, I already have internet permission enabled – Timothy Ayodele Jan 15 '21 at 13:02
  • @TimothyAyodele more information to show that it is different from the other question is needed to figure this out. Can you confirm you have an internet connection on ur emulator – safaiyeh Jan 15 '21 at 15:54
  • 1
    Thanks @safaiyeh for your response. All of a sudden its working again. Initially I checked the internet connection, and I was able to send mails while the problem persisted. But after tweaking some other parts of my other codes to run asynchronously, which is not connected to the function at all, I suddenly discovered its working again. Probably it was some internet issues blocking it before. Thanks for your help. – Timothy Ayodele Jan 16 '21 at 04:21
  • Great glad you found a solution! – safaiyeh Jan 16 '21 at 15:09

0 Answers0