-->
Page 1 of 2

what is conn

PostPosted: Fri May 26, 2017 12:23 pm
by fsankar
I am trying to analyse the following code but please can someone tell me where conn came from?
I am missing something. its a function name but then it seem to be more than that . where is it defined?
Thanks
Franklin


-- a simple HTTP server
srv = net.createServer(net.TCP)
srv:listen(80, function(conn)
conn:on("receive", function(sck, payload)
print(payload)
sck:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1> Hello, NodeMCU.</h1>")
end)
conn:on("sent", function(sck) sck:close() end)
end)

Re: what is conn

PostPosted: Fri May 26, 2017 1:03 pm
by atexit8
That cannot be the entire code.

Re: what is conn

PostPosted: Fri May 26, 2017 1:12 pm
by fsankar
That cannot be the entire code. ......
Thanks for the reply. I don't know if there is more code but here is another application I clipped off another site. I asked the author but he did not get back to me as yet
Franklin

-- Rui Santos
-- Complete project details at http://randomnerdtutorials.com
-- ESP8266 Server

print("ESP8266 Server")
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid="test",pwd="12345678"});
print("Server IP Address:",wifi.ap.getip())

sv = net.createServer(net.TCP)
sv:listen(80, function(conn)
conn:on("receive", function(conn, receivedData)
print("Received Data: " .. receivedData)
end)
conn:on("sent", function(conn)
collectgarbage()
end)
end)

Re: what is conn

PostPosted: Fri May 26, 2017 4:34 pm
by atexit8
The link you gave leads to just a website not any particular project.

And that code is all wrong.