-->
Page 1 of 2

Handling of timeout with net.socket:send()

PostPosted: Mon Mar 27, 2017 3:22 pm
by FrankX
I am using net.socket:send() to retrieve web content.
Occasionally there is no response without receiving a disconnect.
This leaves my application waiting indefinitely.
I have created a timer which is re-triggered every successful reception.
Bu what should I do in the timeout case?
If I reconnect the application stops: PANIC: unprotected error in call to Lua API (already connected)
How do I know if the connection is still open?
More in general: how can I deal with such errors (PANIC), preventing an application failure like shown above?

Re: Handling of timeout with net.socket:send()

PostPosted: Tue Mar 28, 2017 2:15 am
by devsaurus
FrankX wrote:More in general: how can I deal with such errors (PANIC), preventing an application failure like shown above?

Catching the error with pcall() could be a possibility: https://www.lua.org/pil/8.4.html But I've never used it myself so far.

Re: Handling of timeout with net.socket:send()

PostPosted: Fri Mar 31, 2017 2:28 am
by FrankX
I tried using pcall() but still program execution stops in the same way.
It seems pcall() is not able to catch any error.

Example:
Code: Select allif pcall(print(a..a)) then
    print("OK")
else
    print("NG")
end

Execution stops in the same way as without pcall().

Could this be a NodeMCU firmware issue?

Update
Answer to myself: no :-)
I was using pcall() incorrectly.
This works:
Code: Select allif pcall(function() print(a..a) end) then
    print("OK")
else
    print("NG")
end

Re: Handling of timeout with net.socket:send()

PostPosted: Fri Mar 31, 2017 5:52 am
by devsaurus
Excellent :D