Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem")
- modem.open(123) -- Open channel 123 to send and receive messages
- -- Record the start time
- local startTime = os.clock()
- modem.transmit(123, 123, "ping")
- print("Ping sent. Waiting for response...")
- -- Introduce a short delay to simulate processing time
- os.sleep(0.01) -- 10 milliseconds delay
- -- Wait for a response
- local _, _, _, _, response = os.pullEvent("modem_message")
- -- Record the end time
- local endTime = os.clock()
- if response == "pong" then
- -- Calculate round-trip time in milliseconds
- local roundTripTime = (endTime - startTime) * 1000
- print("Pong received!")
- print(string.format("Round-trip time: %.2f ms", roundTripTime))
- else
- print("No response or incorrect response received.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement