- Sun Dec 28, 2014 1:45 am
#5822
How best to handle this? My code needs to send a series of GETs to a server, but I'm not getting how to wait for the first connection to close before moving on to the next one. So far it only works when doing one GET. If I add any more in sequence the module restarts.
By adding
to the receive function it speeds up the process considerably, but it's not enough. It needs some kind of wait loop to prevent a new connection from being created until the last one closes, and none of the usual while loops make any difference. The module just crashes and restarts. I also tried Connection: close. That crashed also.
Code: Select allconn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) conn:close() conn=nil end)
conn:on("disconnection", function() print("disconnected") end)
conn:connect(80,'<IP>')
conn:send("GET /insert.php?mode=insert&sensor="..sid1.."&value="..val1.." HTTP/1.1\r\n")
conn:send("Host: <hostname>\r\n")
conn:send("Accept: */*\r\n")
--conn:send("Connection: close")
conn:send("\r\n")