Saturday, September 2, 2023

UDP Pinger testing

 Objective: 

In this assignment, you will write a client ping program in Python. Your client will send a simple ping message to a server, receive a corresponding pong message back from the server, and determine the delay between when the client sent the ping message and received the pong message. This delay is called the Round-Trip Time (RTT). The functionality provided by the client and server is similar to the functionality provided by standard ping program available in modern operating systems. However, standard ping programs use the Internet Control Message Protocol (ICMP) Here we will create a nonstandard (but simple!)  

Method UDP-based on :

1. Generate a random sequence number.

2. Create a ping message with the sequence number & the current time.

3. Send the ping message to the server.

4. Set a timeout of 1 second.

5. Try to receive a response from the server.

6. If a response is received, print it.

7. Calculate and print the round-trip time (RTT).

8. If no response is received within 1 second, print "Request timed out".

Techniques 

1. Create a UDP Ping Server Python program alter Compile 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 simulated to be lost. Study this code carefully, as it will help you write your ping client program.

2. When the server program is running, you should see loop listening for incoming UDP packets. When a packet comes in and if a randomized integer is greater than or equal to 11, the server simply capitalizes the encapsulated data and sends it back to the client.

+ Source code for UDP Server

import random

from socket import * 

serverSocket = socket(AF_INET, SOCK_DGRAM) 

serverSocket.bind(('127.0.0.1', 5090)) 

print("Started UDP server on ip: 127.0.0.1 and port 5090") 

while True: 

rand = random.randint(0, 10)

 message, address = serverSocket.recvfrom(1024) 

 message = message.upper() 

 if rand < 4: 

     continue 

 serverSocket.sendto(message, address) 


-------------------------------------------------------------------------------------------------Result 




Type : Python UDPServer.py


UDPClient.py 






Share:

0 comments:

Post a Comment