ที่นี่เราจะดูว่า Python สามารถใช้เพื่อรับ Round Trip Time (RTT) ได้อย่างไร RTT คือเวลาที่ใช้โดยการเดินทางทั้งหมดของสัญญาณ หมายถึง เวลาระหว่างเวลาเริ่มต้นที่ส่งสัญญาณและเวลารับสัญญาณตอบรับ
ผลลัพธ์ RTT จะแตกต่างกันไปตามพารามิเตอร์ต่างๆ เช่น
- อัตราการถ่ายโอนข้อมูลของฝั่งผู้ส่ง
- ลักษณะของสื่อส่งสัญญาณ
- ระยะทางจริงระหว่างผู้ส่งและผู้รับ
- จำนวนโหนดระหว่างผู้ส่งและผู้รับ
- ปริมาณการรับส่งข้อมูลบน LAN
- จำนวนคำขอที่จัดการโดยจุดกลาง
โค้ดตัวอย่าง
import time
import requests
import sys
deffind_roundtriptime(url):
initial_time = time.time() #Store the time when request is sent
request = requests.get(url)
ending_time = time.time() #Time when acknowledged the request
elapsed_time = str(ending_time - initial_time)
print('The Round Trip Time for {} is {}'.format(url, elapsed_time))
find_roundtriptime(sys.argv[1]) ผลลัพธ์
$ python3 319.RoundTripTime.py https://www.tutorialspoint.com/ The Round Trip Time for https://www.tutorialspoint.com/ is 0.8301455974578857 $ python3 319.RoundTripTime.py https://www.google.com The Round Trip Time for https://www.google.com is 0.5217089653015137 $