gravitowl

Update

Mar 6th, 2021 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. json = require "json"
  2. local ws, err = http.websocket("ws://localhost:8082")
  3.  
  4. if err then
  5. print(err)
  6.  
  7. elseif ws then
  8. print("[TURTLE] > Connected")
  9. print("Which file would you like to request?")
  10. local file = read()
  11. print("[TURTLE] > Requesting files...")
  12.  
  13. local sendMsg = {
  14. type = "requestFile",
  15. file = file
  16. }
  17. ws.send(json.encode(sendMsg))
  18. local message = ws.receive()
  19. local fileCont = json.decode(message)
  20.  
  21. if fileCont.type == "file" then
  22. fileCont = fileCont.file
  23.  
  24. local newFile = fs.open(file, "w")
  25. newFile.write(fileCont)
  26. newFile.close()
  27.  
  28. print("[TURTLE] > Succesfully downloaded "..file)
  29. elseif fileCont.type == "error" then
  30. print("[TURTLE] > Error: "..fileCont.error)
  31. end
  32. end
  33.  
  34. ws.close()
Add Comment
Please, Sign In to add comment