Assig 2 Documentation
Assig 2 Documentation
Assig 2 Documentation
Erik S.:
import libraries
loop 10 times
send message to server
print ping information
if timeout
print timeout message
close socket
John F.:
import libraries
except if timeout
print timeout message
close socket
Levi R.:
import all from socket
import time
The following for loop will send this message 10 times with a 1-second
timeout, effectively "pinging" the server:
Start timer.
Construct a packet with the appropriate destination address & send it
to the process' socket.
Print
"Ping statistics for [serverName]:
Packets: Sent = X, Received = Y, Lost = Z (?% Loss),
Approximate round trip times in mili-seconds:
Minimum = XXms, Maximum = YYms, Average = ZZms
"
Each member's pseudocode featured a similar approach to the problem. Levi's pseudocode was the
most in-depth and provided the framework for our initial design. However, in writing the client program
we diverged from this pseudocode in some ways after reaching a more thorough understanding of the
requirements.
The only required network steps for setup are noted below:
5. Test plan
As there is no user input for running the client program, testing was done first using a user input string,
allowing us to test different length messages.
6. Test results
Although the difference in packet size was too small to show any changes in the time measurements,
the display of bytes did properly change in the program output when different length messages were
entered. In addition, we took one example output and walked through each EstRTT, DevRTT, and
timeout and did the calculations by hand to ensure that the formulas in use by our program were
correct.
Below is a screenshot of of our program in action:
7. Show the final code
# UDPPingerClient.py
# Creates the client socket with parameters for the address family and the socket type(UDP or TCP)
clientSocket = socket(AF_INET, SOCK_DGRAM)
numPings = 10
previousERTT = 0
previousDRTT = 0
firstERTT = 0
# Stores time when message is being sent and sends the message
t1 = time.perf_counter()
clientSocket.sendto(message + str(t1).encode(), (serverName, serverPort))
try:
# Attempts to recieve a message from the server, if there is an exception, jumps to the exception
handler
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
# Stores time when message was recieved and adds it to the timeLog
t2 = time.perf_counter()
timeLog.append(t2 - t1)
# Toggle firstERTT on after the previousERTT has been assigned its initial value
if firstERTT == 0:
previousERTT = timeLog[-1]
firstERTT = 1
# Calculates the new ERTT/DRTT and stores in previousERTT/DRTT for the next ping
newERTT = ((1 - 0.125) * previousERTT) + (0.125 * timeLog[-1])
previousERTT = newERTT
# Prints the client message & reply message from the server & provides statistics on the ping
print("Message: " + message.decode() + str(t1))
print("Reply from '" + serverName + "' " + str(t2) + " '" + modifiedMessage.decode() + "' | bytes=" +
str(getsizeof(modifiedMessage))
+ " time=" + str(round(timeLog[-1]*1000,2)) + "ms" + " EstRTT=" + str(round((newERTT * 1000),2))
+ "ms"
+ " DevRTT=" + str(round((newDRTT * 1000),2)) + "ms" + " timeout=" + str(round((newERTT +
(4*newDRTT))*1000,2)) + "ms\n")
except:
print("Message: " + message.decode() + str(t1))
print("Request timed out\n")