Advertisement
xX-AAAAAAAAAA-Xx

ComputerCraft VoidNet Ping Test Client

Sep 1st, 2024 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. modem.open(123) -- Open channel 123 to send and receive messages
  3.  
  4. -- Record the start time
  5. local startTime = os.clock()
  6.  
  7. modem.transmit(123, 123, "ping")
  8. print("Ping sent. Waiting for response...")
  9.  
  10. -- Introduce a short delay to simulate processing time
  11. os.sleep(0.01) -- 10 milliseconds delay
  12.  
  13. -- Wait for a response
  14. local _, _, _, _, response = os.pullEvent("modem_message")
  15.  
  16. -- Record the end time
  17. local endTime = os.clock()
  18.  
  19. if response == "pong" then
  20.     -- Calculate round-trip time in milliseconds
  21.     local roundTripTime = (endTime - startTime) * 1000
  22.     print("Pong received!")
  23.     print(string.format("Round-trip time: %.2f ms", roundTripTime))
  24. else
  25.     print("No response or incorrect response received.")
  26. end
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement