C Program to calculate the Round Trip Time (RTT)

CServer Side ProgrammingProgramming

Given an Url address of any website; the task is to calculate the round trip time of a website.

Round Trip Time(RTT) is the total time or the length of a time which is taken to send a signal plus the time taken to receive the acknowledgement of that signal to be received. This time also consist of the propagation times between two points of a signal.

An end user can determine his/her round trip time from an IP address by pinging that address.

The Round Trip time’ result depends upon the following reasons −

  • The Transmission medium.
  • The presence of Interface in the circuit.
  • Number of nodes from the source to the destination.
  • Amount of traffic.
  • Physical Distance from the source to the destination.
  • Nature of the transmission medium(wireless, fiber optic, etc.).
  • Number of requests.
  • Presence of interface in the circuit.

Generally the duration of Round Trip Time will be in milliseconds and we displaying output in Seconds.

Example

Input: www.tutorialspoint.com
Output: Time taken:0.3676435947418213
Input: www.indiatoday.in
Output: Time taken:0.4621298224721691

Approach we will be using to solve the given problem −

  • Take the input string of the URL whose RTT(Round Trip Time) we want to calculate.
  • Record the time before requesting the URL and store it into a variable.
  • Send the request.
  • Record the time after receiving acknowledgement.
  • Compare both the times we will get the RTT.

Algorithm

Start
   Step 1 -> import time
   Step 2 -> import requests
   Step 3 -> define a function def roundtriptime(url):
      Set t1 = time.time()
      Set req = requests.get(url)
      Set t2 = time.time()
      Set t = str(t2-t1)
      Print Time taken
   Step 4 -> Initialize url = "http://www.tutorialspoint.com"
   Step 5 -> Call function roundtriptime(url)
Stop

Example

import time
import requests
# Function to calculate the roundtriptime
def roundtriptime(url):
   # time when the signal is sent
      t1 = time.time()
      req = requests.get(url)
   # time when the acknowledgement
   # is received
      t2 = time.time()
   # total time taken
      t = str(t2-t1)
      print("Time taken:" + t)
   # url address
      url = "http://www.tutorialspoint.com"
      roundtriptime(url)

Output

Time taken:0.3676435947418213
raja
Published on 20-Nov-2019 15:25:17
Advertisements