22.06.2017, 12:24
Hello
do somebody know:
- how can I check currently connected tcp ports?
- how can I reach the socket which is created and permanent used in resident script via event script?
The solution is necessary for Sony Bravia TV. I must have permanent tcp connection to have ability to read status when TV is off. So for this solution I've prepared the resident script 0s:
But sometimes I want send command e.g. switch on but from event-based script. How can I reach currently port from other script?
do somebody know:
- how can I check currently connected tcp ports?
- how can I reach the socket which is created and permanent used in resident script via event script?
The solution is necessary for Sony Bravia TV. I must have permanent tcp connection to have ability to read status when TV is off. So for this solution I've prepared the resident script 0s:
Code:
require('socket')
if not sock_bravia then
-- bravia IP
ip = '192.168.2.102'
sock_bravia = socket.tcp()
sock_bravia:settimeout(3)
res, err = sock_bravia:connect(ip, 20060)
end
-- power-status
cmd = '*SEPOWR################\n' -- Check status power
if res then
res, err = sock_bravia:send(cmd)
if res then
res, err = sock_bravia:receive()
if res then
log('receive OK: ' .. tostring(res)) -- received ok
else
log('receive failed: ' .. tostring(err)) -- receive failed
end
else
log('send failed: ' .. tostring(err)) -- send failed
end
else
log('connect failed: ' .. tostring(err)) -- connect failed
end
os.sleep(5)
But sometimes I want send command e.g. switch on but from event-based script. How can I reach currently port from other script?