Question: while True: #Establish the connection print ( 'Ready to serve. . . ' ) connectionSocket, addr = serverSocket . accept( ) try: message = connectionSocket

 while True: #Establish the connection print ( 'Ready to serve. .

while True: #Establish the connection print ( 'Ready to serve. . . ' ) connectionSocket, addr = serverSocket . accept( ) try: message = connectionSocket . recv(1024) filename = message . split ( ) [1] f = open(filename [1: ]) outputdata = f. read( ) #Send one HTTP header line into socket header = \\\ HTTP/1.1 200 0K\ \ ' connectionSocket . send (header . encode ( ) ) #Send the content of the requested file to the client for i in range(0, len(outputdata) ) : connectionSocket . send (outputdata[i] . encode( ) ) connectionSocket . send ("\\\\" . encode( ) ) connectionSocket . close( ) except IOError : #Send response message for file not found connectionSocket . send ( 'HTTP/1.1 404 Not Found\\\\\\\\' . encode ( ) ) errorMessage = '

404 Not Found

\\\ ' connectionSocket . send(errorMessage . encode ( ) ) connectionSocket . send (b' \\\\\\\\' )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!