Advertisement
krzys_h

Przesyłanie plików przez RedNet v1.0

Aug 16th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. local tArgs = { ... }
  2. if tArgs[1] == "wyslij" then
  3.  rednet.open("top")
  4.  print("Oczekiwanie na drugi komputer!")
  5.  print("Wpisz na nim 'pliki odbierz " .. os.computerID() .. "'")
  6.  wait = true
  7.  id = -1
  8.  while wait do
  9.   id2, msg = rednet.receive()
  10.   if msg == "GET_FILE" then
  11.    wait = false
  12.    id = id2
  13.   end
  14.  end
  15.  print("Polaczono!")
  16.  rednet.send(id, tArgs[2])
  17.  print("Wyslano nazwe pliku: " .. tArgs[2])
  18.  plik = fs.open(tArgs[2], "r")
  19.  dane = plik.readAll()
  20.  rednet.send(id, dane)
  21.  plik.close()
  22.  print("Gotowe!")
  23. elseif tArgs[1] == "odbierz" then
  24.  rednet.open("top")
  25.  print("Laczenie...")
  26.  rednet.send(0+tArgs[2], "GET_FILE")
  27.  id, msg = rednet.receive(5)
  28.  if msg == nil then
  29.   print("Nie ma polaczenia!")
  30.   return
  31.  end
  32.  plik = fs.open(msg, "w")
  33.  print("Odbieranie pliku " .. msg)
  34.  idd, dane = rednet.receive()
  35.  print("Zapisywanie danych")
  36.  plik.write(dane)
  37.  plik.close()
  38.  print("Zakonczono")
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement