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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 23:30, skywil8981
Step 1: choose your topics review the project milestone reflections you submitted for modules 1 through 4. choose the one major idea or concept from each module that you feel most applies to your life. in addition, choose an important concept from module 5 that applies to your life. step 2: write your guidebook for each module: write a catchy headline that clearly and concisely sums up your chosen idea or concept write a brief explanation that includes a description of the concept, why it is important, and how it can be applied to your life to make a positive impact choose an exciting, powerful, or engaging image that illustrates your concept remember, you are writing one for each module, so you will have a total of five headlines, five descriptions, and five images. step 3: design your guidebook choose a format to present your digital guidebook. there are many 21st century tools available for creating and submitting your work in the online environment. for more information on tools your school uses, contact your instructor or visit the web 2.0 tools area.
Answers: 3
image
Computers and Technology, 22.06.2019 08:00, luclaymom805
Aplan to budget time for studying and activities is referred to as a study routine. study habits. study skills. a study schedule.
Answers: 1
image
Computers and Technology, 24.06.2019 17:00, yobanajk
Aman travel 200m towards east< br /> from his house then takes left< br /> to turn and moves 200 m north< br /> find the displacement & distance.< br />
Answers: 3
image
Computers and Technology, 25.06.2019 00:30, alinton06
What is a typeface? a. a collection of similar text b. a collection of similar fonts c. a collection of similar designs d. a collection of similar colors e. a collection of similar images
Answers: 1
You know the right answer?
Another similar application to the UDP Ping would be the UDP Heartbeat. The Heartbeat can be used to...

Questions in other subjects:

Konu
Mathematics, 01.08.2019 04:20
Konu
Mathematics, 01.08.2019 04:30