So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By fsankar
#66360 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)
User avatar
By fsankar
#66363 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)
Last edited by fsankar on Tue May 30, 2017 7:50 pm, edited 1 time in total.
User avatar
By atexit8
#66366 The link you gave leads to just a website not any particular project.

And that code is all wrong.