--remote
clients = {}
function clr()
term.clear()
term.setCursorPos(1,1)
end
local function openRednet()
for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
rednet.open(side)
return side
end
end
print("no modem present")
end
local function searchForNewClients()
while true do
rednet.broadcast("newhost")
os.startTimer(15)
local event, id, message, distance = os.pullEvent()
if event == "rednet_message" and message == "pairing" then
rednet.send(id,"connected " .. os.getComputerID())
clients[table.getn(clients)] = id
return true
elseif event == "timer" then
return false
end
end
end
local function main()
while true do
clr()
sleep(5)
end
end
local function background()
while true do
searchForNewClients()
os.sleep(10)
end
end
--Main
side = openRednet()
if side == nil then
print("no modem found")
else
parallel.waitForAll(main(), background())
while true do
clr()
print("Enter the command")
term.setCursorPos(2,3)
local command = read()
rednet.broadcast(command)
term.setCursorPos(2,5)
print("Sending ...")
sleep(0.25)
end
end
Comments