18.07.2024, 12:55
Try this. It will try sending the data again if the first send call failed due to a closed socket or any other error. Remove log() calls once you get it working.
Code:
if not server then
require('user.lutron')
require('socket')
server = socket.udp()
server:setsockname('127.0.0.1', 5485)
function send(data)
if not sock then
sock, err = lutron_login()
if not sock then
log('lutron login failed', err)
end
end
if sock then
res, err = sock:send(data)
if res then
return true
end
log('lutron send failed', err)
sock:close()
sock = nil
end
end
end
data = server:receive()
if data then
if not send(data) then
send(data)
end
end