Question: The code below simulates a really busy server that accepts sentences as requests and returns capitalized sentences as responses. This code is also available as

The code below simulates a really busy server that accepts sentences as requests and returns capitalized sentences as responses. This code is also available as a text attachment, and must not be altered.

 import random 

from time import sleep 

from socket import * 

BUSY_PERCENT = 50

serverPort = 12000 

                def get_busy(): 

                                  random_number = random.randint(0, 100) 

                                  if random_number < BUSY_PERCENT: 

                                  print("Getting busy ...") 

                                  sleep(1) 

serverSocket = socket(AF_INET, SOCK_DGRAM) 

serverSocket.bind((’’, serverPort)) 

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

                  while True: 

                                  get_busy() 

                                  message, clientAddress = serverSocket.recvfrom(2048) 

                                  print(’Received request:\n’, message.decode(), ’\nfrom client:\n’, clientAddress) 

                                  modifiedMessage = message.decode().upper() 

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

                                  get_busy()

You need to implement three clients that do 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 up to 1 second for a response from the server. If a response is received within this time, it prints the response. Otherwise, it retries after a delay. The three clients will have three delay strategies:
  1. No delay. The request is resent immediately without any backoff.
  2. Exponential backoff. In this strategy, the delay for attempt 0 (initial attempt) is 0, for attempt 1 (first retry) it is a random number of seconds selected from {0, 1}, for attempt 2 it is a random number of seconds selected from {0, 1, 2, 3}, for attempt 3 it is a random number of seconds selected from {0, 1, 2, 3, 4, 5, 6, 7}, and so on.
  3. Linear backoff. In this strategy, the delay for attempt 0 is 0, for attempt 1 it is a random number of seconds selected from {0, 1}, for attempt 2 it is a random number of seconds selected from {0, 1, 2}, for attempt 3 it is a random number of seconds selected from {0, 1, 2, 3}, for attempt 4 it is a random number of seconds selected from {0, 1, 2, 3, 4} and so on.
  • In each case, the client gives up and moves on to the next request at the end of 10 attempts.
  • At the end, the client prints out the average number of attempts per message. The attached file SampleOutput.txt shows what a sample run of this client should produce.

REQUIRED
1. Three client programs, named NoBackoffClient.py, ExponentialBackoffClient.py and LinearBackoffClient.py.

2. A report comparing the average number of attempts required in each of the three strategies.

EXTRA
1. Pick the best strategy from the previous section, and launch n instances (n = 2, 3, 4, 5) of the same client by launching the same client program in n different terminals. Measure how the average number of attempts increases as n increases from 1 to 5. Include a table and/or graph in your report and interpret the results.

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The request involves implementing three distinct client programs each with a specified retry strategy Below I outline a conceptual overview along with ... 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 Programming Questions!