Skip to main content
留学咨询

辅导案例-CSCI 330:

By May 15, 2020No Comments

CSCI 330: Computer Networking Spring 2020 Proj #3 Due 3/5/2020@11:59:59pm Algorithm Design document: 30pts Code: 70pts A Simple Web-Server In this assignment you will gain experience with socket programming by implementing a simple web-server. The web-server will parse properly formatted HTTP request messages and return properly formatted HTTP reply messages. Sample web-site content has been provided to test your implementation. Please read the sections that follow carefully and make sure to invest the time in designing your algorithm and testing your code. Remember to implement and test things incrementally. This will be graded based on two components (1) 30% of your grade will represent your algorithm as expressed in your algorithm design document, (2) 70% of your grade will represent you code (solves the problem, code design and readability). Setting up 1. On Blackboard, locate Project 3 2. Download and unzip the file entitled “WebServerContent.zip” This will create a folder called “WebServerContent” that contains the content for a stunning (currently single page) web-site. 3. Verify the website content by starting your Web-browser and using it to open (file open) the “index.html” file inside of the directory “WebServerContent” 4. Follow the assignment below by implementing your Web-Server code in a python file called “FirstNameLastNameWebServer.py” If your name is Mary Smith, that would be MarySmithWebServer.py. When writing the code for your webserver, please use port 1025 as the port number for your server. It is important that your FirstNameLastNameWebServer.py file be placed inside of the WebServerContent directory. Preparing for the Assignment Remember to think about what your web-server will do by writing out the algorithm it will follow. An algorithm is a numbered list of steps written in understandable statements and or mathematical expressions. Of particular importance is that your web- server must know how to parse a properly formatted HTTP request message. Your web- server must also know how to return a properly formatted HTTP reply message. Please refer to section 2.2.3, HTTP Message Format, in the textbook for the HTTP message request and response formats. Handing in your assignment (due 3/5/2020@11:59:59pm) 1. Write a document describing your algorithm (MS-Word or PDF) 2. Put your document in your WebServerContent directory 3. Make sure your program FirstNameLastNameWebServer.py is in your WebServerContent folder and is tested and runs. To get credit, your webserver must run. The instructor will not debug your code. 4. Compress your WebServerContent directory as a filename FirstNameLastName.zip 5. Submit via Blackboard The Assignment: Socket Programming Assignment: Web Server Review section 2.7.2 and try the socket programming example for yourself. In this lab, you will learn the basics of socket programming for TCP connections in Python: how to create a socket, bind it to a specific address and port, as well as send and receive a HTTP packet. You will also learn some basics of HTTP header format. You will develop a web server that handles one HTTP request at a time. Your web server should accept and parse the HTTP request, get the requested file from the server’s file system, create an HTTP response message consisting of the requested file preceded by header lines, and then send the response directly to the client. If the requested file is not present in the server, the server should send an HTTP “404 Not Found” message back to the client. Code Below you will find the skeleton code for the Web server. This is a guide on how to structure your code. The places requiring your attention are marked with #Fill in start and #Fill in end. Each place may require one or more lines of code. Running the Server You will run your server in the same directory in which the content is located. Run the server program. Determine the IP address of the host that is running the server (e.g., 192.168.101.26). From another host on the same network, open a browser and provide the corresponding URL. For example: http://192.168.101.26:1025/index.html “index.html” is the name of the starting place for web-sites. Note also the use of the port number after the colon. You need to replace this port number with whatever port you have used in the server code. In the above example, we have used the port number 1025. The browser should then display the contents of index.html that you verified when you opened it using your browser’s “file open” command. If you omit “:1025”, the browser will assume port 80 and you will get the web page from the server only if your server is listening at port 80. When handing in your assignment, please make sure it works on port 1025. Note how your web-server is contacted multiple times, once for each image. As a test, convince yourself by also printing out the object that is being requested at the server. Then try to get a file that is not present at the server. Your browser should display a “404 Not Found” message. Information on the Web You may consult any sources on the Internet for reference material on python programming. This does not mean finding a solution and copying it. For example, you might lookup a reference on how to parse a text file in Python or how to run a Python executable from the command line. If you are on Windows, the program Cygwin may be of help to you in providing an elegant command line environment. If you use a reference off the internet, you must cite it in your document. Skeleton Python Code for the Web Server #import socket module
from socket import *
 serverSocket = socket(AF_INET, SOCK_STREAM) #Prepare a sever socket
 #Fill in start #Fill in end
 while True: #Establish the connection print ‘Ready to serve…’ connectionSocket, addr = #Fill in start #Fill in end try: #retrieve incoming GET request message from client message = #Fill in start #parse filename from incoming GET request filename= …
 f = open(filename[1:]) #read file data from disk outputdata= … #Fill in end #Send one HTTP header line into socket #Fill in start
 #Fill in end #Send the content of the requested file to the client for i in range(0, len(outputdata)): connectionSocket.send(outputdata[i]) connectionSocket.close() except IOError: #Send response message for file not found #Fill in start #Fill in end
 #Close client socket #Fill in start #Fill in end serverSocket.close()

admin

Author admin

More posts by admin