Question

In: Computer Science

In this assignment, you will develop a simple Web server in Python that is capable of...

In this assignment, you will develop a simple Web server in Python that is capable of processing only one request. Specifically, your Web server will (i) create a connection socket when contacted by a client (browser); (ii) receive the HTTP request from this connection; (iii) parse the request to determine the specific file being requested; (iv) get the requested file from the server’s file system; (v) create an HTTP response message consisting of the requested file preceded by header lines; and (vi) send the response over the TCP connection to the requesting browser. If a browser requests a file that is not present in your server, your server should return a “404 Not Found” error message.

In the Companion Website, we provide the skeleton code for your server. Your job is to complete the code, run your server, and then test your server by sending requests from browsers running on different hosts. If you run your server on a host that already has a Web server running on it, then you should use a different port than port 80 for your Web server.

PLEASE ANSWER COMPLETELY FOR THUMBS UP. PLEASE DON'T LEAVE ANYTHING EMPTY.

Solutions

Expert Solution

from socket import *
serverPort=80
serverSocket = socket(AF_INET, SOCK_STREAM)

#server socket

serverSocket.bind(('',serverPort))
serverSocket.listen(1)
print 'the web server is up on port:',serverPort

#for connection
while True:
print 'Ready to serve...'
connectionSocket, addr = serverSocket.accept()

try:

message = connectionSocket.recv(1024)
print message,'::',message.split()[0],':',message.split()[1]
filename = message.split()[1]
print filename,'||',filename[1:]
f = open(filename[1:])
outputdata = f.read()
print outputdata

#header line to socket
connectionSocket.send('\nHTTP/1.1 200 OK\n\n')
connectionSocket.send(outputdata)

#sending requested file
for i in range(0, len(outputdata)):
connectionSocket.send(outputdata[i])
connectionSocket.close()

#message for file not found

except IOError:
connectionSocket.send('\nHTTP/1.1 404 Not Found\n\n')
connectionSocket.send('\nHTTP/1.1 404 Not Found\n\n')


Related Solutions

How do I make a simple TCP python web client and web server using only "import...
How do I make a simple TCP python web client and web server using only "import socket"? Basically, the client connects to the server, and sends a HTTP GET request for a specific file (like a text file, HTML page, jpeg, png etc), the server checks for the file and sends a copy of the data to the client along with the response headers (like 404 if not found, or 200 if okay etc). The process would be: You first...
Web Server is the computer that stores Web Server Software and Website. If you are running...
Web Server is the computer that stores Web Server Software and Website. If you are running some service like Food Panda which type of Hosting Server will be used. Answer your question by discussion and comparison of different types of web hosting? If you have low budget so what will be the best possible hosting plan in this situation? Justify your answer by logical reasoning.
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and show they will translate and run. Experience error messages when you enter bad syntax the interpreter cannot understand. Discussion: The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you...
Develop a Python program that brings together APIs and web scraping. Be creative. Pick something you...
Develop a Python program that brings together APIs and web scraping. Be creative. Pick something you are interested in - a hobby, a job, history, cooking, travel, sports, a foreign language, music, art, whatever you have some passion about. Find an API that connects with your interest. Write a Python program that demonstrates the use of that api AND does some web scraping as well. It must include the ability to download images to your computer. Submit the following to...
Discuss the main similarity and difference between a dedicated web server and a co-located web server....
Discuss the main similarity and difference between a dedicated web server and a co-located web server. Group of answer choices Both of them are mainly used for small to medium-size web sites. Both of them are mainly used for large to enterprise-size web sites. Both of them are kept and connected to the Internet at the web host provider's location. One of them is kept and connected to the Internet at the web host provider's location, while the other is...
Describe the process involving the transmission of a Web page from a Web server to a...
Describe the process involving the transmission of a Web page from a Web server to a user’s computer.
Python: High school assignment, please keep simple In python: Use the following initializer list to create...
Python: High school assignment, please keep simple In python: Use the following initializer list to create an array: twainQuotes = ["I have never let my schooling interfere with my education.", "Get your facts first, and then you can distort them as much as you please.", "If you tell the truth, you don't have to remember anything.", "The secret of getting ahead is getting started.", "Age is an issue of mind over matter. If you don't mind, it doesn't matter. "]...
Develop a client /server talk application in C or C++. You should run your server program...
Develop a client /server talk application in C or C++. You should run your server program first, and then open another window if you use loopback to connect the local host again, or you may go to another machine to run the client program that will connect to the server program. In this case you must find the server’s IP address first, and then connect to it. If you use loopback, your procedure may look like: ➢ Server Server is...
Make a modest or simple Web page using Python flask. The basic components of HTML should...
Make a modest or simple Web page using Python flask. The basic components of HTML should be included. The Web page should have at least 3 Headings(<h1>), paragraph (<p>), comments (<!-- -->), ordered list, unordered list, three links to website, and should display time & date. Example: <html>     <head>         <title>Page Title</title>     </head> <body>     ..new page content.. </body> </html>
AWS screenshot of a view of the web browser connection to your web server via the...
AWS screenshot of a view of the web browser connection to your web server via the load balancer (step 5 of this lab document).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT