# CS代考程序代写 cache python Problem 1

Problem 1
ELEC 331 Computer Communications Problem Set 2
Due Date: Friday morning, February 26, 2021, at 9 am (PST)
Question P18 on page 170 of the eText (Kurose and Ross, 8th edition).
Problem 2
Consider Figure 2.12 in page 109 of the eText (Kurose and Ross, 8th edition). Assume there are in total N
clients in the institutional network that are sending HTTP requests. The average request rate from each of
the N clients to the origin servers is K requests per second. Assume different clients are requesting different
objects. The average object size is 750,000 bits. Also suppose that average Internet delay (i.e., the average
amount of time it takes when the router on the Internet side of the access link forwards an HTTP request to
one of the origin servers until it receives the response) is 3 seconds. Model the total average response time as
the sum of the average access delay (that is, the delay from Internet router to institution router) and the
average Internet delay. For the average access delay, use ∆ , where ∆ is the average time required to (1−∆β)
send an object over the access link and β is the arrival rate of objects to the access link. a) Find the total average response time.
b) Now suppose a cache is installed in the institutional LAN. Suppose the hit rate is p, and the response time is zero if the HTTP request can be satisfied by the cache. Determine the total response time.
Problem 3
In this assignment, you will develop a TCP server and a TCP client. Specifically, your TCP client will (i) collects a string variable from the keyboard input; (ii) send the string variable to the TCP server; and (iii) receive the response from the TCP server over the TCP connection. Your TCP server will (i) create a connect socket when contacted by the TCP client; (ii) receive the string variable sent by the TCP client; (iii) generate a reward based on the string variable sent by the TCP client. The rules for determining the reward are shown in Table 1; and (iv) inform the TCP client about the reward by sending a response over the TCP connection to the TCP client.
1

Table 1: Reward
Note that, when determining the reward based on Table 1, you need to differentiate between uppercase letters and lowercase letters. For example, the uppercase ’C’ should be assigned with a reward of 1 whereas the lowercase ’c’ should be assigned with a reward of −1.
For this assignment, you may use TCPClient.py and TCPServer.py that are presented in Section 2.7.2 of the eText (Kurose and Ross, 8th edition) as the skeleton codes. You can also write your own codes.
What to Hand in
For this problem, you will hand in the codes for both your TCP client and TCP server. The reward received from the TCP server should be displayed at your TCP client (e.g., using Python print function). You need to provide the screenshots at the TCP client verifying that your codes works as required. There is no output requirement for your TCP server. The codes must include sufficient comment statements.
Problem 4
In this problem, you will learn the basics of socket programming for UDP in Python. You will learn how to send and receive datagram packets using UDP sockets and also, how to set a proper socket timeout. Throughout the problem, you will gain familiarity with a Ping application and its usefulness in computing statistics such as packet loss rate.
You will first study a simple Internet ping server written in Python, and implement the corresponding client. The functionality provided by these programs is similar to the functionality provided by standard ping programs available in modern operating systems. However, these programs use a simpler protocol, UDP, rather than the standard Internet Control Message Protocol (ICMP) to communicate with each other. The ping protocol allows a client machine to send a data packet to a remote machine, and have the remote machine return the data back to the client unchanged (an action referred to as echoing). Among other uses, the ping protocol allows hosts to determine round-trip times to other machines.
You are given the complete code for the Ping server below. Your task is to write the Ping client.
Server Code
The following code fully implements a ping server. You need to compile and run this code before running your client program. You do not need to modify this code.
In this server code, some of the client’s packets are simulated to be lost. You should study this code carefully, as it will help you implement your Ping client.
String variable sent by the TCP Client
Reward
’A’
3
’B’
2
’C’
1
Otherwise
−1
2

1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19 20 21
22 23 24 25
# UDPPingerServer . py
# We will need the following module to generate randomized lost packets
import random
from socket import ∗
# Create a UDP socket
# Notice the use of SOCKDGRAM for UDP packets
serverSocket = socket (AF INET, SOCKDGRAM)
# Assign IP address and port number to socket
serverSocket.bind((’’, 12000))
while True :
# Generate random number in the range of 0 to 49
rand = random.randint(0, 49)
# 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 18, we consider the packet lost and do not respond