-
• #2
Tue 2020.03.24
Has an attempt to place a console.log() statement just after the http.get request at L1a to see if anything is being detected/returned within the callback?
or use of the debugger?Related content with fix
Could it be related to https
-
• #3
The code
console.log("back from network?",res)
didn't print anything.tp.get("http://www.pur3.co.uk/hello.txt", function (res) { console.log("back from network?",res) let str = ''; res.on('data', chunk => { console.log("chunk",chunk); str += chunk; }); res.on('end', () => { console.log("result: ---> ", str); }); });
In the Mehtod recv(), I did got datas and retruned them. But where these datas go I really don't know, and how do they go back to http.get response body?
console.log("[recv data]", r)
return r;
-
• #4
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.'
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?
-
• #5
This is the request message
GET /hello.txt HTTP/1.1
User-Agent: Espruino 2v04.401
Connection: close
Host: http://www.pur3.co.ukAnd 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,1I 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.txt", 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[sckt]) 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!" -
• #6
Tue 2020.03.24
It is working as expected as text 'Hello World!' is returned.
As at L20 the string is available in local scope, why not assign it to a global var at that point?
Better:
POST not GETSee link in post #4 and:
Concept
https://codeburst.io/javascript-what-the-heck-is-a-callback-aba4da2deced
https://www.dashingd3js.com/lessons/javascript-callback-functions
https://stackoverflow.com/questions/5263785/how-to-use-callback-function-in-java-script-functions
Now I use a SIM7600CE for 4G connection. The modules didn't adapt for this kind of sim card.
So I have to write my own module for it.
Now I can get response datas in this Method:
I think this part is the place where return datas to http.get().
But I can't recieve any datas in this place.
Do you have any introductions about how the datas flow in the network?