So a VERY simple example - the function is stored in a FILE so as to minimise RAM use. It is called once only after power up assuming I have an IP address.... and listens and responds on port 4000 in this case.
So it reads the status of a string l1. it can also change the state of that string.... back and forth. It really is working fine - but it's using up RAM and not giving it back... any idea WHY? I absolutely need to stop this to make it work... BUG? or ME?
If I run it constantly it seems to not use up any RAM but if I start and stop the APP on the phone - it seems to use up RAM... I can't imagine WHERE that would be.... so ultimately the program will fail after enough interruptions.. Happy to admit I'm lost on this one..
file.remove("mylistener.lua")
file.open("mylistener.lua","w")
file.writeline([[l1="0\n"]])
file.writeline([[sv=net.createServer(net.TCP, 90) ]])
file.writeline([[sv:listen(4000,function(c)]])
file.writeline([[c:on("receive", function(sck, pl) ]])
file.writeline([[print(pl) ]])
file.writeline([[if (pl=="GO1\n") then c:send(l1) ]])
file.writeline([[elseif pl=="YES1\n" then l1="1\n" c:send("OK\n") ]])
file.writeline([[elseif pl=="NO1\n" then l1="0\n" c:send("OK\n") ]])
file.writeline([[else c:send("0\n") ]])
file.writeline([[end]])
file.writeline([[end)]])
file.writeline([[end)]])
file.close()
My real program has 4 variables and 4 sets of controls but the result is the same - see output - note half way down the RAM drops
8456
GO1
8456
GO2
8456
GO3
8456
GO4
8456
GO1
8456
GO2
6112
GO1
6112
GO3
6112
GO4
6112
GO2
6112
GO1
6112
GO3
6112