Guest User

Client

a guest
Mar 1st, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. -- client
  2. local modemSide = "right"
  3. local serverId = 6
  4. rednet.open(modemSide)
  5.  
  6. local function updateFile(name)
  7.   print('sending file request for: '..name)
  8.   rednet.send(serverId, name)
  9.   while true do
  10.     print('waiting for response')
  11.     local event, id, msg, dist = os.pullEvent("rednet_message")
  12.     if id == serverId then
  13.       msg = textutils.unserialize(msg)
  14.       if not msg.success then
  15.         printError(msg.message)
  16.       else
  17.         local handle = fs.open(msg.path, "w")
  18.         if not handle then
  19.           printError("Failed to open file to update")
  20.         elseif not msg.message then
  21.           printError("No contents received")
  22.         else
  23.           handle.write(msg.message)
  24.           handle.close()
  25.         end
  26.       end
  27.       return -- exit out of the function, we are done here
  28.     else
  29.       printError('response from unknown client')
  30.     end
  31.   end
  32. end
  33.  
  34. updateFile("cake")
  35. updateFile("can")
  36. updateFile("someFile")
  37.  
  38. rednet.close(modemSide)
Advertisement
Add Comment
Please, Sign In to add comment