Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Open Rednet on a specific side (use "top", "bottom", "left", "right", "front", or "back")
- rednet.open("top")
- -- Set up the monitor on the side of the server (replace "right" with your monitor's side)
- local monitor = peripheral.wrap("right")
- monitor.clear()
- -- Display the server's ID on the monitor
- monitor.setCursorPos(1, 1)
- local serverId = os.getComputerID()
- monitor.write("Server ID: " .. serverId)
- -- Display input prompt for server ID
- monitor.setCursorPos(1, 3)
- monitor.write("Enter Server ID to send file:")
- -- Function to display received file info and sender's ID on the monitor
- local function displayReceivedInfo(senderId, filename)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Server ID: " .. serverId)
- monitor.setCursorPos(1, 3)
- monitor.write("Sender ID: " .. senderId)
- monitor.setCursorPos(1, 5)
- monitor.write("Received File:")
- monitor.setCursorPos(1, 6)
- monitor.write(filename)
- end
- while true do
- -- Wait for user input for server ID
- local selectedServerId = tonumber(read())
- -- Listen for incoming connections from the specified server ID
- local senderId, message, protocol = rednet.receive("file_transfer")
- -- Check if the received message is a file
- if senderId == selectedServerId then
- -- Save the received file with a specific name
- local file = fs.open("received_file.txt", "w")
- file.write(message)
- file.close()
- print("File received and saved as 'received_file.txt'")
- -- Display received file info and sender's ID on the monitor
- displayReceivedInfo(senderId, "received_file.txt")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement