Post your best Lua script examples here

User avatar
By yes8s
#4435
ThomasW wrote:Hi,
Maybe you get different network settings on the forwarded path than locally and the module's tcp buffer overflows (see viewtopic.php?f=18&t=642 - with slightly different symptoms). I tried your code with different filesizes - worked up to ~ 2800 btyes (which results in about 2 packets at the standard MTU of 1500) then the result was garbled. Lowering the MTU to 900 resulted in exactly what you described - no output at all (couldn't even see a response with tcpdump on the wire). I don't see a solution here besides rewriting the code to send packets line by line at the moment :(

Thomas


How exactly does one modify the MTU? I did want to test with a smaller packet size but I wasn't exactly sure how this would work in Lua - there is not much configuration here and the lua network api's are not exactly elaborate. Do I just issue a conn:close() inside the conn:on("receive"....) function after sending some data?
User avatar
By yes8s
#4466
yes8s wrote:
ThomasW wrote:Hi,
Maybe you get different network settings on the forwarded path than locally and the module's tcp buffer overflows (see viewtopic.php?f=18&t=642 - with slightly different symptoms). I tried your code with different filesizes - worked up to ~ 2800 btyes (which results in about 2 packets at the standard MTU of 1500) then the result was garbled. Lowering the MTU to 900 resulted in exactly what you described - no output at all (couldn't even see a response with tcpdump on the wire). I don't see a solution here besides rewriting the code to send packets line by line at the moment :(

Thomas


How exactly does one modify the MTU? I did want to test with a smaller packet size but I wasn't exactly sure how this would work in Lua - there is not much configuration here and the lua network api's are not exactly elaborate. Do I just issue a conn:close() inside the conn:on("receive"....) function after sending some data?


OK, I've confirmed my issue is the same as what Thomas mentioned. I'm continuing the discussion on his post: viewtopic.php?f=18&t=642&p=4465
User avatar
By ThomasW
#4467
yes8s wrote:
ThomasW wrote:Hi,
Maybe you get different network settings on the forwarded path than locally and the module's tcp buffer overflows (see viewtopic.php?f=18&t=642 - with slightly different symptoms). I tried your code with different filesizes - worked up to ~ 2800 btyes (which results in about 2 packets at the standard MTU of 1500) then the result was garbled. Lowering the MTU to 900 resulted in exactly what you described - no output at all (couldn't even see a response with tcpdump on the wire). I don't see a solution here besides rewriting the code to send packets line by line at the moment :(

Thomas


How exactly does one modify the MTU? I did want to test with a smaller packet size but I wasn't exactly sure how this would work in Lua - there is not much configuration here and the lua network api's are not exactly elaborate. Do I just issue a conn:close() inside the conn:on("receive"....) function after sending some data?


I played with the MTU on *my* side to see if I could reproduce your problem. AFAIK, there is no way to control any network settings on the lua side. It seems that we also dont have control over the sending - all we can do is set up a callback for "sent", pass a (hopefully small enough) piece of data to socket:send() and send the next chunk once we get called (hopefully) by the "sent"-event of the previous one. We can't really *wait* for the packet to be sent - from my understanding, the api just passes the data to the networking stack who builds up the packet and decides when to *actually* send it out (probably either at a full buffer or after a small timeout (which we cant't provide, alas)). Somebody please correct me if I'm wrong with this, it's just based on observations and some knowledge from working with a SPI-ethernet device some years ago.

Anyway, perhaps you can try the following with your remote connection to see if this really is the problem:

Code: Select allfunction testserver()
   local srv=net.createServer(net.TCP,100)
   srv:listen(80,function(conn)
      conn:on("receive",function(conn,payload)
         local isopen=false

         conn:on("sent",function(conn)
            if not isopen then
               isopen = true
               file.open("bigfile.html", "r")
            end
            local line = file.readline()
            if line then
               conn:send(line)
            else
               file.close()
               conn:close()
               conn=nil
            end
         end)

         conn:send("HTTP/1.1 200 OK\r\n")
         conn:send("Content-type: text/html\r\n")
         conn:send("Connection: close\r\n\r\n")
      end)
   end)
end
testserver()

Did work over here with a reduced MTU on my side.

Thomas
User avatar
By ok1cdj
#4995 There was talk about images.

I know that we have only 150 kb of free space. I have idea how to have more than 479 icons under 100 kb. I'm using
http://fortawesome.github.io/Font-Awesome/ on PC. The EOT format of all icons have 56 kb + full CSS 22kb (you can make your own css much smaller only with things which do you need or also smaller font with your favorites icons).

I need find the way how to correctly transfer binary file to filesystem now and try it. Any idea ??