Coding Project 2: UDP Pinger
In this lab, you will learn the basics of socket programming forUDP in Python. You will learn how to send and receive datagrampackets using UDP sockets and also, how to set a proper sockettimeout. Throughout the lab, you will gain familiarity with a Pingapplication and its usefulness in computing statistics such aspacket loss rate.
You will first study a simple Internet ping server written inthe Python, and implement a corresponding client. The functionalityprovided by these programs is similar to the functionality providedby standard ping programs available in modern operating systems.However, these programs use a simpler protocol, UDP, rather thanthe standard Internet Control Message Protocol (ICMP) tocommunicate with each other. The ping protocol allows a clientmachine to send a packet of data to a remote machine, and have theremote machine return the data back to the client unchanged (anaction referred to as echoing). Among other uses, the ping protocolallows hosts to determine round-trip times to other machines.
You are given the complete code for the Ping server below. Yourtask is to write the Ping client.
Server Code
The following code fully implements a ping server. You need tocompile and run this code before running your client program.You do not need to modify this code.
In this server code, 30% of the client’s packets are simulatedto be lost. You should study this code carefully, as it will helpyou write your ping client.
# UDPPingerServer.py
# We will need the following module to generate randomized lostpackets 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(('', 12000))
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 comingfrom message, address = serverSocket.recvfrom(1024)
# Capitalize the message from the client
message = message.upper()
# If rand is less is than 4, weconsider the packet lost and do not respond if rand < 4:
continue
# Otherwise, the server responds
serverSocket.sendto(message,address)
The server sits in an infinite loop listening for incoming UDPpackets. When a packet comes in and if a randomized integer isgreater than or equal to 4, the server simply capitalizes theencapsulated data and sends it back to the client.
Packet Loss
UDP provides applications with an unreliable transport service.Messages may get lost in the network due to router queue overflows,faulty hardware or some other reasons. Because packet loss is rareor even non-existent in typical campus networks, the server in thislab injects artificial loss to simulate the effects of networkpacket loss. The server creates a variable randomized integer whichdetermines whether a particular incoming packet is lost or not.
Client Code
You need to implement the following client program.
The client should send 10 pings to the server. Because UDP is anunreliable protocol, a packet sent from the client to the servermay be lost in the network, or vice versa. For this reason, theclient cannot wait indefinitely for a reply to a ping message. Youshould get the client wait up to one second for a reply; if noreply is received within one second, your client program shouldassume that the packet was lost during transmission across thenetwork. You will need to look up the Python documentation to findout how to set the timeout value on a datagram socket.
Specifically, your client program should
(1) send the ping message using UDP (Note: Unlike TCP, you do notneed to establish a connection first, since UDP is a connectionlessprotocol.)
(2) print the response message from server, if any
(3) calculate and print the round trip time (RTT), in seconds, ofeach packet, if server responses
(4) otherwise, print “Request timed outâ€
During development, you should run the UDPPingerServer.py onyour machine, and test your client by sending packets tolocalhost (or, 127.0.0.1). After you have fully debuggedyour code, you should see how your application communicates acrossthe network with the ping server and ping client running ondifferent machines.
Message Format
The ping messages sent to the server in this project areformatted in a simple way. The client message is one line,consisting of ASCII characters in the following format:
Ping sequence_number time
where sequence_number starts at 1 and progresses to 10for each successive ping message sent by the client, andtime is the time when the client sends the message.
------------------------------------
I cannot get my version to work, please follow theinstructions.