Advertisement
DOGGYWOOF

client w connecting reuqest

Jan 7th, 2024
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. -- Client side (Updated to react to server's connection request)
  2. -- Make sure the modem is open on the side you're using
  3. rednet.open("left") -- Replace "left" with the side where your modem is placed
  4.  
  5. -- Function to send a file to the server
  6. local function sendFile(serverID, fileName)
  7. local file = fs.open(fileName, "r")
  8. if file then
  9. local content = file.readAll()
  10. file.close()
  11.  
  12. local message = {
  13. fileName = fileName,
  14. fileContent = content
  15. }
  16.  
  17. rednet.send(serverID, message, "file_transfer")
  18. print("File sent to server.")
  19. else
  20. print("File not found.")
  21. end
  22. end
  23.  
  24. -- Replace with the actual server ID
  25. local serverID = 123 -- Replace with the actual server's ID
  26.  
  27. -- Replace with the file you want to send
  28. local fileName = "example.txt" -- Replace with the file you want to send
  29.  
  30. -- Check if permission is needed before sending the file
  31. rednet.send(serverID, "PermissionRequest", "permission")
  32. local _, message, _ = rednet.receive()
  33.  
  34. if message == "PermissionGranted" then
  35. sendFile(serverID, fileName)
  36. else
  37. print("Permission denied. File not sent.")
  38. end
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement