首页 > > 详细

辅导program编程、辅导Java,Python程序语言、c++程序辅导辅导留学生 Statistics统计、回归、迭代|帮做C/C++编程

WebServer
Our final project is a group assignment. You will need to find a partner. No one can work alone and there can only be one group of 3 (ok’ed by me). Not finding a partner will mean getting a 0 on the assignment.

A web server is a program that connects to a port (networking), listens for requests and sends the appropriate file to the requestor. Web servers must respond to requests and create a response using the “HTTP protocol (https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol). For our web server, we will use only the most critical portions of the protocol:
A request (which you will receive) will consist of the word “GET”, a space, a path to the file, a space and then the version of HTTP which is implemented (you can ignore this) all on the first line. There will be other lines to the request – you can ignore them.
A response (which you will generate) will consist of: the string “HTTP/1.0 “, followed by code (200 for OK or 404 for file not found), a new line, then “Content-Length: “ + the number of bytes of the response followed by 2 new lines.
An example session follows. Red is the request, blue is the response:
GET /test2.html HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
HTTP/1.0 200 OK
Content-Length:6

test2

Your program should run on port 8000 (port 80, which is the usual for web applications, will be blocked by your firewall). Your program should take a path as a parameter (and fail with a usage message if there is no parameter). That path will be the path that your web server will use to serve files. For example – let’s say that the path is /home/mphipps. If I try to access localhost:8000/secret/data.html, your web server will look at: /home/mphipps/secret and try to serve data.html. If the file is there, it should return it with a “200 OK” message, as above. If the file does not exist, you should return a “404 Not Found” message with a pre-designed response (could be a file or could be a hard coded message).
Your web server should launch a new thread for each request. You should use POSIX commands for files (no fopen/fclose/etc) and pthreads for threadedin. Your web server should be an infinite loop of waiting for and processing requests.
Hints:
Don’t wait – start this soon.
My code was around 150 lines. Yours should not be much longer or shorter.

Rubric Poor OK Good Great
Comments None/Excessive (0) “What” not “Why”, few (5) Some “what” comments or missing some (7) Anything not obvious has reasoning (10)
Variable/Function naming Single letters everywhere (0) Lots of abbreviations (5) Full words most of the time (8) Full words, descriptive (10)
Structure Globals everywhere, indentation doesn’t match braces {}, no helper functions (0) Any 2 of:
Too many globals
Indentation wrong
Missing helper functions (5) Any 1 of:
Too many globals
Indentation wrong
Missing helper functions (13) Few/no globals, indentation correct, helper functions(20)
Threading No threading (0) One thread per request (10)
Networking No networking (0) Some attempt at setup/listening (10) Setup, Listening and teardown work correctly (20)
File Handling None/uses “f” style functions (0) Uses open/close/read (10) Uses open/close/read/stat (20)
HTTP No attempt at HTTP (0) Reads requests (3) Reads requests, handles 200 responses (7) Requests, 200, 404 (10)

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp2

联系我们 - QQ: 99515681 微信:codinghelp2
© 2021 www.7daixie.com
程序辅导网!