Question: Run the server program and determine the IP address of the host that is running the server (e.g., 128.238.251.26). To verify that we actually received

Run the server program and determine the IP address of the host that is running the server (e.g., 128.238.251.26).  To verify that we actually received the contents of the HTML file from the server.

#import socket module from socket import import sys # In order to

 

#import socket module from socket import import sys # In order to terminate the program serverSocket = socket (AF_INET, SOCK_STREAM) #Prepare a sever socket #Fill in start serverSocket.bind(', serverPort)) serverSocket.listen(1) #Fill in end while True: #Establish the connection print('Ready to serve...') connectionSocket, addr = serverSocket.accept() try: message = connection.Socket.recv(1024) filename message.split() [1] f = open(filename[1:]) outputdata = f.read() f.close() #Send one HTTP header line into socket #Fill in start connectionSocket.send(' HTTP/1.1 200 OK ') #Fill in end #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 #Fill in start connectionSocket.send(" HTTP/1.1 404 Not Found') #Fill in end #Close client socket #Fill in start connectionSocket.close() #Fill in end serverSocket.close() sys.exit() #Terminate the program after sending the corresponding data

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution To run the server program and determine the IP address of the host that is running the serv... View full answer

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!