- A simple http client
conn=net.createConnection(net.TCP, false)
- OK - make a variable called CONN and create a connection using the TCP protocol and not secure. Clear enough.
conn:on("receive", function(conn, pl) print(pl) end)
- OK - define a receiver function to be called when the connection has a RECEIVE event.
So the ":on" syntax is how you made a receiver for an event, I guess.
conn:connect(80,"121.41.33.127")
- now here I get fuzzy. Is "connect" a method telling it to connect? Surely "createConnection() is doing that? And if so, why aren't he port number and IP address parameters of that call?
conn:send("GET / HTTP/1.1\r\nHost: www.nodemcu.com\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")
- and this one baffles me too. Is "send" a method of the connection object "conn"?
Is it called inline, at this point in the code, to implement the GET request?
Surely, it would have to wait until the connection is made (asynchronously).
So what causes this line of code to run?
I have similar issues with other examples. I have reviewed several node.js videos, and they make perfect sens, but the syntax is critically different, implementing a different hierarchy. I've looked at some Lua tutorials too but no joy.
I'm an experienced programmer, but I'm knocking on a bit and may be getting senile, but if anyone can shed some light, or point me to the light switch, I'd be grateful.