The code below simulates a really busy server that accepts

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.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

GradeEssays.com
We are GradeEssays.com, the best college essay writing service. We offer educational and research assistance to assist our customers in managing their academic work. At GradeEssays.com, we promise quality and 100% original essays written from scratch.
Contact Us

Enjoy 24/7 customer support for any queries or concerns you have.

Phone: +1 213 3772458

Email: support@gradeessays.com

© 2024 - GradeEssays.com. All rights reserved.

WE HAVE A GIFT FOR YOU!

15% OFF 🎁

Get 15% OFF on your order with us

Scroll to Top