Advertisement
DOGGYWOOF

server

Jan 6th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. -- Open Rednet on a specific side (use "top", "bottom", "left", "right", "front", or "back")
  2. rednet.open("top")
  3.  
  4. -- Set up the monitor on the side of the server (replace "right" with your monitor's side)
  5. local monitor = peripheral.wrap("right")
  6. monitor.clear()
  7.  
  8. -- Display the server's ID on the monitor
  9. monitor.setCursorPos(1, 1)
  10. local serverId = os.getComputerID()
  11. monitor.write("Server ID: " .. serverId)
  12.  
  13. -- Display input prompt for server ID
  14. monitor.setCursorPos(1, 3)
  15. monitor.write("Enter Server ID to send file:")
  16.  
  17. -- Function to display received file info and sender's ID on the monitor
  18. local function displayReceivedInfo(senderId, filename)
  19. monitor.clear()
  20. monitor.setCursorPos(1, 1)
  21. monitor.write("Server ID: " .. serverId)
  22. monitor.setCursorPos(1, 3)
  23. monitor.write("Sender ID: " .. senderId)
  24. monitor.setCursorPos(1, 5)
  25. monitor.write("Received File:")
  26. monitor.setCursorPos(1, 6)
  27. monitor.write(filename)
  28. end
  29.  
  30. while true do
  31. -- Wait for user input for server ID
  32. local selectedServerId = tonumber(read())
  33.  
  34. -- Listen for incoming connections from the specified server ID
  35. local senderId, message, protocol = rednet.receive("file_transfer")
  36.  
  37. -- Check if the received message is a file
  38. if senderId == selectedServerId then
  39. -- Save the received file with a specific name
  40. local file = fs.open("received_file.txt", "w")
  41. file.write(message)
  42. file.close()
  43. print("File received and saved as 'received_file.txt'")
  44.  
  45. -- Display received file info and sender's ID on the monitor
  46. displayReceivedInfo(senderId, "received_file.txt")
  47. end
  48. end
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement