I would like to set up a big computercraft network with one main computer using wireless modems and rednet api. Though I was not able to find any tutorials - all of the tutorials I found were using Craft os 1.6 or lower (I am using 1.7). The wiki was not much help either.

Thank you in advance.


Using 3 basic rednet functions - open(side), broadcast(message, protocol) and receive(protocol, timeout), it is possible to implement this.

Control Computer code:

print('Main Computer')
print('  Enter any command to broadcast to slaves')

rednet.open('top') -- Open modem on top

while true do -- Run this forever
  io.write('>>> ')
  command = io.read() -- Read a command from stdin
  if command == 'exit' then -- If it's exit
    rednet.close('top') -- Close top modem
    return -- Exit
  rednet.broadcast(command, 'slave')  -- Otherwise, broadcast the command with protocol slave

Slave code:

rednet.open('top') -- Same, open top
while true do -- Run forever
  id, data = rednet.receive('slave') -- Receive message under protocol 'slave'
  print('Received command ' .. data) 
  if data == 'quit' then -- If it's quit
    rednet.close('top') -- Cleanup, close top modem
    return -- Exit
  elseif string.match(data, 'math .+') then -- Regex: command starts with math
    equation = string.match(data, 'math (.+)') -- Regex: get actual equation
    print(equation .. ' = ' .. loadstring('return ' .. equation)()) -- Eval it. I'm not responsible for attacks. 
  • what's slave code? – technikfe Aug 27 '16 at 18:24
  • The slave is the computer being controlled, much like a slave – Universal Electricity Aug 28 '16 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.