subject

Another similar application to the UDP Ping would be the UDP Heartbeat. The Heartbeat can be used to check if an application is up and running on the client side and to report one-way packet loss. The client continuously sends a message acting as a heartbeat in the UDP packet to the server, which is monitoring the heartbeat (i. e., the UDP packets) of the client. Upon receiving the packets, the server calculates the time difference. If the heartbeat packets are missing for some specified time interval, the server can assume that the client application has stopped working. Implement the UDP Heartbeat (both client and server). You will need to modify the given udppingserver. py, and your udppingclient. py.
The client program sends a ping message to the server using UDP every 5 seconds.
The server program monitors if a ping is received from the client. If the ping from the client was absent for more than 10 seconds, it prints the message "No pulse after 10 seconds. Server quits".
Current udppingserver. py file:
# udppingserver. py
# We will need the following module to generate randomized lost packets
import random
from socket import *
# Create a UDP socket
# Notice the use of SOCK_DGRAM for UDP packets
serverSocket = socket(AF_INET, SOCK_DGRAM)
# Assign IP address and port number to socket
serverSocket. bind(('', 45678))
while True:
# Generate random number in the range of 0 to 10
rand = random. randint(0, 10)
# Receive the client packet along with the address it is coming from
message, address = serverSocket. recvfrom(1024)
# If rand is less is than 4, we consider the packet lost, do not respond
if rand < 4:
continue
# Otherwise, the server responds
serverSocket. sendto(message, address)
Current udppingclient. py file:
UDPPinglerClient. py
import socket
from socket import AF_INET, SOCK_DGRAM
import time
print 'Running'
serverName = '127.0.0.1' #server set as localhost
clientSocket = socket. socket(AF_INET, SOCK_DGRAM) #create the socket
clientSocket. settimeout(1) #sets the timeout at 1 sec
sequence_number = 1 #variable to keep track of the sequence number
rtt=[] # list to store the rtt values
while sequence_number<=10:
start=time. time() #the current time
message = ('PING %d %d' % (sequence_number, start)) #client message
clientSocket. sendto(message,(serverName, 11046))#client sends a message to the server
try:
message, address = clientSocket. recvfrom(1024) #recieves message from server
elapsed = (time. time()-start) # calculates the rtt
rtt. append(elapsed)
print message
print 'Round Trip Time is:' + str(elapsed) + ' seconds'
except socket. timeout: #if no reply within 1 second
print message
print 'Request timed out'
sequence_number+=1 #incremented by 1
if sequence_number > 10: #closes the socket after 10 packets
mean=sum(rtt, 0.0)/ len(rtt)
print ''
print 'Maximum RTT is:' + str(max(rtt)) + ' seconds'
print 'Minimum RTT is:' + str(min(rtt)) + ' seconds'
print 'Average RTT is:' + str(mean)+ ' seconds'
print 'Packet loss rate is:' + str((10-len(rtt))*10)+ ' percent'
clientSocket. close()

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:30
Write a program that reads the file, then displays the average number of steps taken for each month. (the data is from a year that was not a leap year, so february has 28 days.) your program needs to use at least 3 functions not counting main and display the information in a neat well formatted fashion.
Answers: 3
question
Computers and Technology, 22.06.2019 03:30
Identify at least three types of characteristics that you were asked about as you the computer identify a fruit.
Answers: 3
question
Computers and Technology, 23.06.2019 00:30
If joey was single and his taxable income was $9,500, how much would he pay in taxes each year?
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. peter has launched a website that features baby products. however, clients often find they are unable to access the website because the server is down. which feature of cybersecurity should peter focus on for his website? a. data authenticity b. data privacy c. data availability d. data integrity e. data encryption
Answers: 3
You know the right answer?
Another similar application to the UDP Ping would be the UDP Heartbeat. The Heartbeat can be used to...
Questions
question
Mathematics, 08.12.2019 05:31
question
Mathematics, 08.12.2019 05:31
Questions on the website: 13722363