Question: In this assignment you will develop client/server application for network echoing using the UDP protocol. This application can be used for checking the network connectivity

In this assignment you will develop client/server application for network echoing using the UDP protocol. This application can be used for checking the network connectivity between two computers. The server code was provided in the last recitation and it is also available in this document. Your task is implementing the client code according to the following specifications. Your client code will send 10 consecutive echo massages (based on following specific format). The server, upon the receiving the messages just changes the characters of received message to the upper case and sends the message back to the client. As we discussed in the class in order to simulate the packet loss the server drop 40% of the packets and did not respond to the client.

Server Code (Server_Echo.py)

The following code fully implements the echo server. You need to compile and run this code before running your client program. You do not need to modify this code.

#### The network Echo program , Server side code ####

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))

print("Started UDP server on port 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 coming from message,

address = serverSocket.recvfrom(1024)

# Capitalize the message from the

client message = message.upper()

# If rand is less is than 4, we consider 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 UDP packets. When a packet comes in and if a randomized integer is greater than or equal to 4, the server simply capitalizes the encapsulated data and sends it back to the client.

Client Code

You need to implement the following client program. The client should send 10 echo to the server. You should get the client wait up to one second for a reply; if no reply is received within one second, your client program should assume that the packet was lost during transmission across the network. You will need to look up the Python documentation to find out how to set the timeout value on a datagram socket. Specifically, your client program should

1- Send the echo message using UDP

2- Print the response message from server, if any

3- Calculate and print the round trip time (RTT), in seconds, of each packet, if server responses otherwise, print Request timed out

During development, you should run the server code on your machine, and test your client by sending packets to localhost (or, 127.0.0.1). After you have fully debugged your code, you should see how your application communicates across the network with the echo server and echo client running on different machines.

Message Format

The echo messages in this lab are formatted in a simple way. The client message is one line, consisting of ASCII characters in the following format:

echo sequence_number time

where sequence_number starts at 1 and progresses to 10 for each successive ping message sent by the client, and time is the time when the client sends the message.

What to Hand in

You will hand in the complete client code and screenshots at the client verifying that your ping program works as required.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!