This is my current HTTP Server trial :
if srv ~= nil then srv:close() end
counter=1
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",pr)
conn:on("sent",function(conn) print("package sent, Heap = "..node.heap()) conn:close() end)
end)
function pr(c,pl)
outmsg=nil
counter=counter+1
print (pl)
a,b,n,v = string.find(pl, "([&?]Count)=(%a+)")
outmsg = "HTTP/1.1 200 OK\r\n".."Content-Type: text/html\r\n".."Connection: close\r\n"
outmsg = outmsg.."\r\n".."<!DOCTYPE HTML>\r\n".."<html>\r\n"
outmsg = outmsg.."<h1>This is the header of the page</h1><br />"
if v == "True" then outmsg= outmsg.."Count = "..tostring(counter).."<br />" end
outmsg = outmsg.."</html>"
c:send(outmsg)
end
Questions :
1/ c:send leading do callback
I noticed when submitting multiple c:send statements, I only have one conn:on("sent", callback.
So I am wondering how to initiate the con:close() with multiple sends?
I am now building the outputmessage in a separate string to prevent multiple c:sends
Is that the way one is supposed to work ?
Is my working with outmsg = outmsg.."the string to be added" an efficient way in lua regarding speed and memory usage ?
2/ Connection info
I would like to get some more information of the client connecting.
Is there a possibility to get for example the IP address of the client, maybe using the socket parameter ?
Is there any information (fields, methods) of the socket interface/parameter ?
Kind regards,
Herman