-->
Page 1 of 1

net.socket:on() "sent" callback doesn't work

PostPosted: Tue Mar 21, 2017 1:50 pm
by mscichu
Hi!
Sorry for my english... I don't speak werry well.
I do some project with ESP12E module. I flash NodeMCU firmware from there: https://nodemcu-build.com/ and I write some code. On one ESP I create AP and others: end modules (now only one but I need to connect 80 and more) are clients. I can connect and send data to and from end modules but i have problem with close open sockets and after 55 connections I have ERROR "out of memory". On both sides (AP and clients) code is similiar:
Sending function:
Code: Select allfunction send_wifi(tekst,komenda,zmienna,ip)
    ca=net.createConnection(net.TCP, 0)
    ca:on("sent", function(sck, c) print("Send") sck:close() end)   
    ca:send("START".."="..tekst .. '=' .. komenda .. '=' .. zmienna .. '=END')
    ca:connect(80,"192.168.1." .. ip)
end

Recive:
Code: Select allsv = net.createServer(net.TCP)
sv:listen(80, function(conn)
        local napis
        conn:on("receive", function(conn, receivedData)
        napis = receivedData
        conn:close()
        -- Other CODE

        send_wifi(poczatek,warunek,urzadzenie,someIP)


I try to debug but ESP doesn't go to
Code: Select all    ca:on("sent", function(sck, c) print("Send") sck:close() end)   
after sending data. What I'm doing wrong?

Re: net.socket:on() "sent" callback doesn't work

PostPosted: Wed Mar 22, 2017 8:22 am
by marcelstoer
mscichu wrote:after 55 connections I have ERROR "out of memory"


We recently changed the socket TIME_WAIT configuration to improve that: https://github.com/nodemcu/nodemcu-firmware/pull/1838

-> try a firmware build from the 'dev' branch

mscichu wrote:
Code: Select allsv = net.createServer(net.TCP)
sv:listen(80, function(conn)
        local napis
        conn:on("receive", function(conn, receivedData)
        napis = receivedData
        conn:close()


The socket variable in the on-receive callback function should not be called 'conn' because you've already got a variable with the same name in the outer function (contributes to memory problems). Look at http://nodemcu.readthedocs.io/en/latest ... #example_6 for a good example to implement the server part.

Re: net.socket:on() "sent" callback doesn't work

PostPosted: Wed Mar 22, 2017 9:49 am
by mscichu
marcelstoer wrote:> try a firmware build from the 'dev' branch

Thank you, this work perfect for me, but still doesn't go to sent callback.
Can I change TIME_WAIT using some function in NodeMCU firmware?

marcelstoer wrote:The socket variable in the on-receive callback function should not be called 'conn' because you've already got a variable with the same name in the outer function (contributes to memory problems).

Ok, thank you I will change it.