Question: create UDPClient by using this UDPServer import random from socket import * MESSAGE_DROP_PERCENT = 50 serverPort = 12000 serverSocket = socket(AF_INET, SOCK_DGRAM) serverSocket.bind((, serverPort)) print(The

 create UDPClient by using this UDPServer

import random

from socket import *

MESSAGE_DROP_PERCENT = 50

serverPort = 12000

serverSocket = socket(AF_INET, SOCK_DGRAM)

serverSocket.bind((’’, serverPort))

print(’The server is ready to receive requests’)

while True:

message, clientAddress = serverSocket.recvfrom(2048)

random_number = random.randint(0, 100)

if random_number < MESSAGE_DROP_PERCENT:

continue

print(’Received request:’, message.decode(), ’from client:’, clientAddress)

modifiedMessage = message.decode().upper()

serverSocket.sendto(modifiedMessage.encode(), clientAddress)

Implement a client that does the following:

• It sends 20 messages to the server; the contents of these messages should be as follows (one message per line):

ping message number 0

ping message number 1

ping message number 2

...

ping message number 19

The messages are sent sequentially, i.e., one after the other.

• After sending each message, the client waits 1 second for a response from the server. If a response is received within this time, it prints the response. Otherwise, it simply prints

Timed out !!!

A typical execution of the client code will generate an output that looks like, but is not necessarily identical to, the following (not identical because requests will be randomly dropped by the server):

Sent: ping message number 0

Received: PING MESSAGE NUMBER 0

Sent: ping message number 1

Received: PING MESSAGE NUMBER 1

Sent: ping message number 2

Received: PING MESSAGE NUMBER 2

Sent: ping message number 3

Received: PING MESSAGE NUMBER 3

Sent: ping message number 4

Received: PING MESSAGE NUMBER 4

Sent: ping message number 5

Received: PING MESSAGE NUMBER 5

Sent: ping message number 6

Timed out !!!

Sent: ping message number 7

Received: PING MESSAGE NUMBER 7

Sent: ping message number 8

Received: PING MESSAGE NUMBER 8

Sent: ping message number 9

Received: PING MESSAGE NUMBER 9

Sent: ping message number 10

Timed out !!!

Sent: ping message number 11

Received: PING MESSAGE NUMBER 11

Sent: ping message number 12

Timed out !!!

Sent: ping message number 13

Received: PING MESSAGE NUMBER 13

Sent: ping message number 14

Timed out !!!

Sent: ping message number 15

Received: PING MESSAGE NUMBER 15

Sent: ping message number 16

Received: PING MESSAGE NUMBER 16

Sent: ping message number 17

Received: PING MESSAGE NUMBER 17

Sent: ping message number 18

Timed out !!!

Sent: ping message number 19

Received: PING MESSAGE NUMBER 19

. When a request times out, the client described above simply gives up on that request and moves on to the next request. In reality, a typical client will retry a timed-out request several times before giving up.

1. Update your client code so that every request is attempted NUM TRIES times (a parameter that you will set) before giving up. What would you set NUM TRIES to so that most requests get a response?

2. Explore the relationship between NUM TRIES on the client-side and MESSAGE DROP PERCENT on the server-side.

Step by Step Solution

3.45 Rating (152 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Serverpy import randomfrom socket import MESSAGEDROPPERCENT 10 serverPort 12000serverSocket socketAFINET SOCKDGRAM Below line allows the addressport t... View full answer

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 Mechanical Engineering Questions!