-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
46 lines (34 loc) · 1.24 KB
/
client.py
File metadata and controls
46 lines (34 loc) · 1.24 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
import time
import sys
# Client code makes a request for a webpage, rerouting through server (proxy)
proxies = {
"http": "http://localhost:5001",
"https": "http://localhost:5001"
}
def run_client():
#url = "http://www.stanford.edu"
# url = "http://www.google.com"
#url = "http://www.yahoo.com"
url = "http://www.google.com"
if len(sys.argv) > 1:
url = sys.argv[1]
r = requests.get(url, proxies=proxies)
print(r.text)
# host = socket.gethostname()
# port = 5001
# client_socket = socket.socket()
# client_socket.connect((host, port))
# client_socket.send("Hello from client".encode())
# print(client_socket.recv(1024))
def multi_request():
start_time = time.time()
r1 = requests.get("http://www.google.com", proxies=proxies)
r1_time = time.time()
r2 = requests.get("https://www.stanford.edu/", proxies=proxies) # HTTPS request
r2_time = time.time()
r3 = requests.get("https://www.scs.stanford.edu/20sp-cs244b/", proxies=proxies)
r3_time = time.time()
# LRU: stanford.edu should be in cache, google should not be request stanford again, then request yahoo. SCS should be booted from cache, not stanford
if __name__ == "__main__":
run_client()