Download presentation
Presentation is loading. Please wait.
1
Programming project #4 1 CS502 Spring 2006 Programming Project #4 Web Server CS-502 Operating Systems Spring 2006
2
Programming project #4 2 CS502 Spring 2006 Programming Assignment 1.Build a simple but real web server using sockets; also build a simple web client for testing your server 2.Make your server fork a process for each new request 3.Make your server spawn a new thread for each request
3
Programming project #4 3 CS502 Spring 2006 Purpose To gain some insight into sockets and communication over networks.
4
Programming project #4 4 CS502 Spring 2006 Part 1 – Web Server Create a socket() and bind() it to a port. listen() on that port for requests Wait for requests; upon receipt of a request –accept() the request –Interpret the HTTP request –Find and deliver the page; or return an error –Close the accepted request –Loop back and wait for another request Figure out a way of exiting from the server cleanly.
5
Programming project #4 5 CS502 Spring 2006 Part 1 – Web Server (continued) Command line:- % server [optional port #] Directory is prefixed to every request. –WPI directory for web pages is /www/docs Port is port number for your server –You may specify a default port in your code, but don’t choose one to conflict with another student! –Warning: Unix does not let you reuse ports until after a reasonable waiting period (30 seconds?) A request to your server of http://ccc4.wpi.edu:4242/admissions.html means return the file at /www/docs/admissions.html on port #4242
6
Programming project #4 6 CS502 Spring 2006 Class discussion next week Review experience with using sockets to actually do something. Discuss how to exit server program cleanly.
7
Programming project #4 7 CS502 Spring 2006 Part 1 – Web Client Simple test program that requests web pages and prints out their contents. Use to see what your server is doing. Use to see what another server is actually serving when you request the same pages.
8
Programming project #4 8 CS502 Spring 2006 HTTP commands Your server must interpret HTTP GET command See written project description for examples All command lines must end with CR/LF –i.e., in Unix \r\n Series of HTTP commands ends with blank line –i.e., a stand alone \r\n
9
Programming project #4 9 CS502 Spring 2006 HTTP Response Once you accept a command and have found the page, respond with HTTP success response 200 –See written project description –Be sure to follow with a blank line If you cannot find or read the page, respond with HTTP error response 404 You only need to serve real file pages. –Ignore scripts, etc. WPI’s home page is a script. –Remember: some pages are not all text!
10
Programming project #4 10 CS502 Spring 2006 Sample code See http://www.cs.wpi.edu/~cs502/s06/CodeFragments/ Includes sockserver.c sockclient.c sockreadline.c
11
Programming project #4 11 CS502 Spring 2006 Part 2 – Multi-process Web Server Modify your web server to fork() a process each time it receives a request. This allows it to serve multiple requests in parallel. Test with multiple web clients or browsers in parallel. Be sure to clean up “zombie” processes on the fly –Use wait3() Be sure that your server leaves time for each process to finish before exiting cleanly.
12
Programming project #4 12 CS502 Spring 2006 Part 3 – Threaded Web Server Modify your web server to spawn a thread each time it receives a request. This also allows it to serve multiple requests in parallel. Test with multiple web clients or browsers in parallel. Be sure to threads exit cleanly after finishing with each connection. Be sure that your server leaves time for each thread to finish before exiting cleanly.
13
Programming project #4 13 CS502 Spring 2006 Project Submission Project due at start of class on April 17 (i.e., one week before the last class of the term) Submit via turnin command = ‘ /cs/bin/turnin ’ on CCC machines classname = ‘ cs502 ’ assignment = ‘ project4 ’ Include Code, makefiles, test files or input, test output
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.