This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Tiin57's profile picture

Background Rednet.receive

Started by Tiin57, 16 July 2012 - 01:23 PM
Tiin57 #1
Posted 16 July 2012 - 03:23 PM
I am trying to make a centrally controlled updater for my collection of programs. I already have all of the programs ready but one: the receiver.
It works like this; the router sends out the update signal to all of the computers on the network, and they are then supposed to receive that signal and run the update program. I have all of it down except for the part where the clients receive the signal. How would I make a computer receive a signal without running the rednet.receive as the main program, thus shutting down all other processes until an update is received? (Note: the entire point of this system is to be able to put in a single word into the router and have all of the clients update. Not me running to each client and doing anything to it. They're too far apart and too many to do that.)
Thank you in advance.
kazagistar #2
Posted 16 July 2012 - 03:26 PM
Use os.pullEvent("rednet").
Tiin57 #3
Posted 16 July 2012 - 03:29 PM
I might just be dumb, but it's just waiting for a signal from the router. Here's the router code:

print("This is the update server for TiinOS. Type updateall or exit.")
local v = read()
if v == "updateall" then
rednet.broadcast("go")
elseif v == "exit" then
else
print("Not valid.")
shell.run("updateserver")
end
And the client code.

local m = os.pullEvent("rednet_message")
if m == "go" then
shell.run("getOSa")
else
print("Error.")
end
The goal is to have the client run in the background, not interrupting the main processes of the terminal unless the "go" signal is received.
Here is the getOSa code:


shell.run("delete","getOSauto")
shell.run("pastebin","get","JG37XZcb","getOSauto")
shell.run("getOSauto")
And the getOSauto code:

shell.run("delete","updateserver")
shell.run("pastebin","get","C7YPyD46","updateserver")
shell.run("delete","updateclient")
shell.run("pastebin","get","Ev24W1Zi","updateclient")
shell.run("delete","lock")
shell.run("pastebin","get","BVUKrk29","lock")
shell.run("delete","server2")
shell.run("pastebin","get","Ym7JinQ8","server2")
shell.run("delete","client2")
shell.run("pastebin","get","nmP8vaDx","client2")
shell.run("delete","good")
shell.run("pastebin","get","Vrb0dtHG","good")
shell.run("delete","rednetset")
shell.run("pastebin","get","db5hmf22","rednetset")
shell.run("delete","boblock")
shell.run("pastebin","get","3aKTf3iG","boblock")
shell.run("delete","boblockserver")
shell.run("pastebin","get","rjwZfKFA","boblockserver")
shell.run("delete","getOSa")
shell.run("pastebin","get","tyBYx16c","getOSa")
print("Finished autoupdate.")
MysticT #4
Posted 16 July 2012 - 03:56 PM
Try with parallel. It will look something like:

local function update()
  while true do
    local evt, id, msg = os.pullEvent("rednet_message")
    -- do something with the message
  end
end

parallel.waitForAny(update, function() shell.run("shell") end) -- run the function on the background of a new shell
os.shutdown() -- shutdown when you exit the new shell
Tiin57 #5
Posted 16 July 2012 - 04:06 PM
Ah, most excellent. This worked perfectly. Now to run around to all my computers and set it up…
Thank you.