Download to read offline
![Howdo I construct a pythonweb server usingthis code? #import socket module fromsocket import * serverSocket = socket(AF_INET, SOCK_STREAM) #Prepare a sever socket #Fillinstart #Fillinend while True: #Establishthe connection print 'Readyto serve...' connectionSocket, addr = #Fillinstart #Fillinend try: message = #Fillinstart #Fillinend filename = message.split()[1] f= open(filename[1:]) outputdata = #Fillinstart #Fillinend #Send one HTTP header line into socket #Fillinstart #Fillinend #Send the content ofthe requested file to the client for iinrange(0, len(outputdata)): connectionSocket.send(outputdata[i]) connectionSocket.close() except IOError: #Send response message for file not found #Fillinstart #Fillinend #Close client socket #Fillinstart #Fillinend serverSocket.close()](https://image.slidesharecdn.com/2234-180713125010/75/How-do-I-construct-a-python-web-server-using-this-code-import-socket-module-from-socket-import-1-2048.jpg)
The document outlines a code snippet for constructing a basic Python web server using the socket module. It includes steps for establishing a server socket, accepting connections, reading requested files, and sending HTTP responses. It also notes error handling for when a requested file is not found.