Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code I have filled in thus far: from socket import * import sys if len(sys.argv) while 1: # Start receiving data from the client

image text in transcribed

image text in transcribed

The code I have filled in thus far:

from socket import * import sys

if len(sys.argv)

while 1: # Start receiving data from the client print('Ready to serve...') tcpCliSock, addr = tcpSerSock.accept() print('Received a connection from:', addr) message = tcpCliSock.recv(1024) print(message) # Extract the filename from the given message print(message.split()[1]) filename = message.split()[1].partition("/")[2] print(filename) fileExist = "false" filetouse = "/" + filename print(filetouse) try: # Check wether the file exist in the cache f = open(filetouse[1:], "r") outputdata = f.readlines() fileExist = "true" # ProxyServer finds a cache hit and generates a response message tcpCliSock.send("HTTP/1.0 200 OK ") tcpCliSock.send("Content-Type:text/html ") for i in range(0, len(outputdata)): # Fill in start tcpCliSock.send(outputdata[i]) tcpCliSock.close() #Fill in end print('Read from cache') # Error handling for file not found in cache except IOError: if fileExist == "false": # Create a socket on the proxyserver c = #Fill in start #Fill in end hostn = filename.replace("www.","",1) print(hostn) try: # Connect to the socket to port 80 # Fill in start # Fill in end # Create a temporary file on this socket and ask port 80 for the file requested by the client fileobj = c.makefile('r', 0) fileobj.write("GET "+"http://" + filename + " HTTP/1.0 ") # Read the response into buffer buff = fileobj.readlines() # Create a new file in the cache for the requested file. Also send the response in the buffer to client socket and the corresponding file in the cache tmpFile = open("./" + filename,"wb") for line in buff: tmpFile.write(line); # send the line to the client # Fill in start # Fill in end except: print("Illegal request") else: # HTTP response message for file not found tcpCliSock.send("HTTP/1.0 404 sendErrorErrorError ") tcpCliSock.send("Content-Type:text/html ") tcpCliSock.send(" ") # Close the client and the server sockets tcpCliSock.close() tcpSerSock.close()

Will tcpCliSock.send(outputdata[i]) tcpCliSock.close() generate a response and send data essentially "reading from the cache"?

What about the other Fill in areas?

Code Below you will find the skeleton code for the client. You are to complete the skeleton code. The places where you need to fill in code are marked with #Fill in start and #Fill in end. Each place may require one or more lines of code. Running the Proxy Server Run the proxy server program using your command prompt and then request a web page from your browser. Direct the requests to the proxy server using your IP address and port number. For e.g. http://localhost:8888/www.google.com To use the proxy server with browser and proxy on separate computers, you will need the IP address on which your proxy server is running. In this case, while running the proxy, you will have to replace the "localhost" with the IP address of the computer where the proxy server is running. Also note the port number used. You will replace the port number used here "8888" with the port number you have used in your server code at which your proxy server is listening. Configuring your Browse You can also directly configure your web browser to use your proxy. This depends on your browser. In Internet Explorer, you can set the proxy in Tools Internet Options Connections tab LAN Settings. In Netscape (and derived browsers such as Mozilla), you can set the proxy in Tools options Advanced tab Network tab Connection Settings. In both cases you need to give the Code Below you will find the skeleton code for the client. You are to complete the skeleton code. The places where you need to fill in code are marked with #Fill in start and #Fill in end. Each place may require one or more lines of code. Running the Proxy Server Run the proxy server program using your command prompt and then request a web page from your browser. Direct the requests to the proxy server using your IP address and port number. For e.g. http://localhost:8888/www.google.com To use the proxy server with browser and proxy on separate computers, you will need the IP address on which your proxy server is running. In this case, while running the proxy, you will have to replace the "localhost" with the IP address of the computer where the proxy server is running. Also note the port number used. You will replace the port number used here "8888" with the port number you have used in your server code at which your proxy server is listening. Configuring your Browse You can also directly configure your web browser to use your proxy. This depends on your browser. In Internet Explorer, you can set the proxy in Tools Internet Options Connections tab LAN Settings. In Netscape (and derived browsers such as Mozilla), you can set the proxy in Tools options Advanced tab Network tab Connection Settings. In both cases you need to give the

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions