Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the

Using python 3 to create the UDP Ping Clien and server.

Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT.

The ping message contains 2 4-byte integers and must be encoded in network-byte order as follows1:

  • 4-byte message type with an integer value of 1 or 2

    • Message type = 1 for a ping request (message from client to server)

    • Message type =2 for a ping response (message from server to client)

  • 4-byte sequence number with a unique integer value starting from 12. In the ping response, the server should echo back the clients sequence number.

Both the client and server program should take the following input parameters:

  • IP address of server

  • IP port of server

The client program will read in the above input parameters, and send 10 ping requests consecutively to the server running at the specified IP address and port, waiting for a response each time. After each response is received, the client calculates and prints the RTT for the message. If no response is received within a certain amount of time (one second)3, the client notes that the request timed out and then sends the next request up to the maximum. The program output should print out trace information when data is sent and received, and account for error conditions. Trace output must include:

  • At start of output, print a message indicating the IP address and port of the server being pinged

  • For each ping response received, print RTT along with sequence number of ping message

  • For no ping response, print Message timed out along with sequence number of the ping message

  • After completion, print the following statistics (similar to output of UNIX ping utility);

    • Number of packets sent, received, lost (% loss rate)

    • Min, Max, Average RTT for all acknowledged ping packets

The server will read in the input arguments, bind to the specified IP address and port, and wait in an infinite loop to receive ping requests from the client. On receiving a ping request, the server program will randomly4 decide whether to respond to ping requests to simulate network packet loss. In the case that the server responds, it sends a ping response containing the appropriate message type, and client sequence number. In the case that the server decides not to respond, no ping response is sent, and the server waits for another ping request. To implement random loss, the server should generate a random integer between 0 and 10 and if the result is < 4, do not respond to the packet.

In a ping request, the application data has the following format:

0 1 2 3 4 (bytes)

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

| Message Type (1= request) |

--------------------------------------------------------------------------------

| Message sequence number (e.g. 5) |

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

In a ping response, the application data has the following format:

0 1 2 3 4 (bytes)

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

| Message Type (2 = response) |

--------------------------------------------------------------------------------

| Message sequence number (e.g. 5) |

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Examples of the client program trace output are as follows:

Pinging 127.0.0.1, 12000:

Ping message number 1 timed out

Ping message number 2 RTT: 0.002154 secs

.

Ping message number 10 RTT: 0.000194 secs

Examples of the server program trace output are as follows:

The server is ready to receive on port: 12000

Message with sequence number 1 dropped

Responding to ping request with sequence number 2

Responding to ping request with sequence number 10

Notes:

  1. Timestamp Resolution:

When testing your program, especially when running client and server on the same host, you might find little difference in the timestamp values. The values will depend on the test environment, and timer resolution on your machine. If there are issues, you should simulate longer delays, by adding in a random "wait" or "sleep" function on the server before sending a ping response on receipt of a message.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions