telecom and computer networking

Roz
skeleton.py

#import socket module import socket import sys serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print("Socket Created!!") try: #bind the socket #fill in start #fill in end except socket.error as msg: print("Bind failed. Error Code: " + str(msg[0]) + "Message: " + msg[1]) sys.exit() print("Socket bind complete") #start listening on the socket #fill in start #fill in end print('Socket now listening') while True: #Establish the connection connectionSocket, addr = #fill in start #fill in end print('source address:' + str(addr)) try: #Receive message from the socket message = #fill in start #fill in end print('message = ' + str(message)) #obtian the file name carried by the HTTP request message filename = message.split()[1] print('filename = ' + str(filename)) f = open(filename[1:], 'rb') outputdata = f.read() #Send the HTTP response header line to the socket #fill in start #fill in end #Send the content of the requested file to the client connectionSocket.send(outputdata) #close the connectionSocket #fill in start #fill in end print("Connection closed!") except IOError: #Send response message for file not found #fill in start #fill in end #Close the client socket #fill in start #fill in end serverSocket.close()