You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • I'm actually having a lot of trouble reproducing this with your code. I uploaded it to the board and added the 'Access-Control-Allow-Origin': '*' header so I could access it from another file.

    Then I stuck your polling code in a html file set to call 5 times a second. Any more and it refused to work:

    <html>
    <body>
    <script src="https://code.jquery.com/jquery-1.12­.4.min.js"></script>
    <script>
    var xhr;
    function httpGetAsync(theUrl, jsonpcb, ok, err) {
        if (xhr && xhr.readyState != 4) {
            xhr.abort();
           }
        xhr = jQuery.ajax({
           type:'GET',
           url:theUrl,
           cache:false,
           timeout: (60000),
           crossDomain: true,
           error: err,
           success: ok
        });
    }
    
    setInterval(function() {
      httpGetAsync("http://192.168.1.164/", function(c) {
        console.log("JSON",c);
      }, function(c) {
        console.log("OK",c);
      }, function(c) {
        console.log("ERR",c);
      });
    }, 200);
    </script>
    </body>
    </html>
    

    And then loaded it in 4 windows - so that's 20 requests per second.

    After a bit I started getting the following:

    ERR Object {readyState: 0, status: 0, statusText: "abort"}

    But interspersed with the correctly returned page. After closing the extra windows the board immediately returned to working correctly. So I'd say the behaviour was perfect.

    So I'm thinking this is probably the computer(s) that are requesting data that are still keeping connections open. Which web browser are you using on them?

    When you have problems, could you run:

    global["\xff"].HttpSC.forEach(function(s­,i) {var x=s.svr;s.svr=0;print(i,s);s.svr=x;})
    

    and post the result? It's possible that connections are open and the HTTP header hasn't got through, so Espruino is just leaving sockets open waiting for a response. If so, it might be possible to add a timeout on Espruino's side that would close the connections if the header wasn't received within the first second.

    You could also try:

    global["\xff"].HttpSC.forEach(function(s­) {s.closeNow=true});
    

    That should force Espruino to close all server connections immediately.

About

Avatar for Gordon @Gordon started