Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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

Step: 1

Solution To run the server program and determine the IP address of the host that is running the serv... 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

Computer Networking A Top-Down Approach

Authors: James F. Kurose, Keith W. Ross

5th edition

136079679, 978-0136079675

More Books

Students also viewed these Programming questions