1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 17:40:26 +00:00
opus/sys/apps/mirrorHost.lua

56 lines
1.0 KiB
Lua
Raw Normal View History

2016-12-11 19:24:52 +00:00
require = requireInjector(getfenv(1))
local Socket = require('socket')
local Logger = require('logger')
local process = require('process')
Logger.setScreenLogging()
local args = { ... }
local mon = device[args[1] or 'monitor']
if not mon then
error('Monitor not attached')
end
mon.setBackgroundColor(colors.black)
mon.clear()
while true do
2017-05-09 05:57:00 +00:00
local socket = Socket.server(5901)
2016-12-11 19:24:52 +00:00
print('mirror: connection from ' .. socket.dhost)
local updateThread = process:newThread('updateThread', function()
while true do
local data = socket:read()
if not data then
break
end
for _,v in ipairs(data) do
mon[v.f](unpack(v.args))
end
end
end)
2017-05-10 23:59:09 +00:00
-- ensure socket is connected
2017-05-10 10:11:25 +00:00
process:newThread('pinger', function()
while true do
os.sleep(3)
2017-05-10 23:59:09 +00:00
if not socket:ping() then
2017-05-10 10:11:25 +00:00
break
end
end
end)
2016-12-11 19:24:52 +00:00
while true do
process:pullEvent('modem_message')
if updateThread:isDead() then
break
end
end
print('connection lost')
socket:close()
end