You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Thanks for posting up the code, it's a nice idea! - I just gave it a try.

    What I believe is happening is Unable to create socket happens because you have too many active connections. Espruino via ESP8266 can handle around 4 I believe - but you fire off 3 at the same time.

    While that works normally, if a connection gets slowed down for some reason and isn't closed after 30 seconds, now you're using 4 at once. One more and it'll fail.

    If it's like me, I found that after a while it did start working again?

    function getPrices() {
      symbols.forEach(symbol => {
        let url = `${proxy}${api}${symbol}-${currency}`;
        console.log("Opening socket");
        h.get(url, function(res) {      
          let pricesRaw = "";
          res.on('data', function(d) { pricesRaw += d; });
          res.on('close', () => {
            console.log("Socket closed");
            prices[symbol] = JSON.parse(pricesRaw);
          });
        });
      });
      showPrices();
    }
    

    If you output when a socket opens and when it closes (like above), you'll probably be able to see it happening.

    So... Personally I'd request each of your symbols in turn, after each one has completed - that'll probably make these slightly broken connections far less frequent. You could actually update more often, but could just update each token in turn?

    You could also skip an update if something is already in progress (I believe connections will time out after 60 seconds anyway)

About

Avatar for Gordon @Gordon started