• This might have the solution and a reasonable explanation:

    'On the Internet page there is a simple example of sending data in the URL from a webpage, but it can be unreliable if anywhere between your browser and the Espruino decides to cache the received data.'

    http://www.espruino.com/Posting+Forms



    My suggestion is to post the response data in it's entirety so that others may take a look and compare to what should be in the response packet.


    'how do they go back to'

    Don't know but, could it be the use of the arrow functions not allowing binding to the http response object?

  • This is the request message

    GET /hello.txt HTTP/1.1
    User-Agent: Espruino 2v04.401
    Connection: close
    Host: http://www.pur3.co.uk

    And this is the response message

    RECV FROM:93.93.135.13:80
    +IPD259
    HTTP/1.1 200 OK
    Date: Wed, 25 Mar 2020 02:30:54 GMT
    Server: Apache/2.4.18 (Ubuntu)
    Last-Modified: Fri, 15 Nov 2013 15:42:26 GMT
    ETag: "d-4eb390b887c80"
    Accept-Ranges: bytes
    Content-Length: 13
    Connection: close
    Content-Type: text/plain
    Hello World!
    +IPCLOSE: 0,1

    I tried to put debuggers in two places. In this place, I can't reach the debugger 2.

         debugger;  // 1
        http.get("http://www.pur3.co.uk/hello.tx­t", function(res) {
          debugger;  //2
          let str = ''; 
          res.on('data', chunk => {
            console.log("chunk",chunk);
            str += chunk;
          });
          res.on('end', () => {
            console.log("Get some test request contents: --->   ", str);
          });
        });
    

    And the second place here:

    recv: function (sckt, maxLen) {
        if (sockData[sckt]) {
          console.log("ddddddddddddddd",sockData[s­ckt])
          var r;
          console.log("recv", sockData[sckt].length);
          if (sockData[sckt].length > maxLen) {
            r = sockData[sckt].substr(0, maxLen);
            sockData[sckt] = sockData[sckt].substr(maxLen);
            console.log("recv", sockData[sckt]);
          } else {
            r = sockData[sckt];
            sockData[sckt] = "";
            console.log("recv | socks[sckt]", socks[sckt]);
            if (socks[sckt] == "DataClose") {
              dbg("Got DataClose - forcing close");
              socks[sckt] = "closing";
            }
          }
          console.log("[recv data]", r);
          debugger; // 3
          return r;
        }
        if (socks[sckt] == "closing" || !socks[sckt]) return -1; // close it
        return "";
      },
    

    I can reach debugger 3. And then where the code goes puzzle me so much! What's the relation between Http.get() and recv()?

    debug>step

              return r;
              ^
    

    debug>step
    Value returned is ="Hello World!"

About

Avatar for Robin @Robin started