Posted 26 April 2016 - 12:05 AM
Alright, so, I'm trying to use a program to pair other computers to a host computer via rednet, and then have them do things (specifically in this case, activate a redstone signal.) Right now, as my code is, I start the computer(s) I want to pair, let them wait in a loop, and start the host program on the host computer. It sends the pairing message through to the clients, but when I try to read it on the host when they send it back, it doesn't see any of the messages, resulting in no pairing. I store the id's of the paired computers locally on the host program in a table, so they become un-paired after the program resolves. If anyone could help, I would be full of gratitude for you.
Host program:
Client Program
Any and all help would be appreciated. Thanks!
Host program:
rnModem = "top"
local auth = math.floor(math.random(1,10000))
if rednet.isOpen(rnModem) then
rednet.broadcast(auth)
end
local clientTab = {}
os.startTimer(10)
while true do
event, id, msg, _ = os.pullEvent()
if msg == auth then
for i = 1,#clientTab do
if not id == clientTab[i] and not clientTab[i] == nil then
tI = #clientTab + 1
clientTab[tI] = id
else
clientTab[1] = id
end
end
elseif event == "timer" then
break
end
end
print("There are " ..#clientTab.. " paired computers.")
Client Program
for _,side in pairs(redstone.getSides()) do
if peripheral.getType(side) == "modem" then
if not rednet.isOpen() then rednet.open(side) end
end
end
while true do
local event, id, msg = os.pullEvent()
if event == "rednet_message" and id == 0 then
mNumb = msg
break
end
end
print("Aquired key")
os.startTimer(10)
print("Set timer, sending message")
while true do
event = os.pullEvent()
rednet.broadcast(mNumb)
if event == "timer" then print("Timeout") break end
end
Any and all help would be appreciated. Thanks!