• Run on port 6789 by default, or on whatever port is given as the first command-line argument
  • Accept and parse the HTTP request
  • Get the requested file from the server's file system
  • Files should be obtainable as long as they are in the directory where the program is run from or any subdirectory below that directory
  • Create an HTTP response message consisting of the requested file preceded by header lines. You should inform the client of the paylod size via the Content-Length: header line.
  • Send the response directly to the client
  • If the requested file is not present on the server, the server should send an HTTP "404 Not Found" message back to the client.
% python WebServer.py 1234 Ready to serve on port = 1234 New client: ('127.0.0.1', 50341) File requested: HelloWorld.html Bytes sent: 52 Ready to serve on port = 1234 New client: ('127.0.0.1', 50342) File requested: temp/HelloWorld2.html Bytes sent: 67 Ready to serve on port = 1234 New client: ('127.0.0.1', 50346) File requested: MissingFile.html File not found! Ready to serve on port = 1234 ... % python WebServer.py Ready to serve on port = 6789 ...
  • Name of the server
  • Port the web server is running on
  • Name of page to retrieve
% python WebClient.py WebClient.py <server name> <server port> <page> % python WebClient.py localhost 6789 HelloWorld.html <html> <body> <h1>Hello world!</h1> </body> </html> % python WebClient.py cs.mtech.edu 80 index.html <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>302 Found</title> </head><body> <h1>Found</h1> <p>The document has moved <a href="http://cs.mtech.edu/main">here</a>.</p> <hr> <address>Apache/2.2.16 (Debian) Server at cs.mtech.edu Port 80</address> </body></html> % python WebClient.py cs.mtech.edu 80 main/

Page last updated: October 14, 2013

Lab: Simple Web Server

Csc 364 - computer networks - weinman.

  • Introduce Python programming
  • Practice basic UNIX-style socket programming
  • Learn a little about the HTTP protocol
  • Reinforce knowledge about filesystem security
  • Section 2.2 in Kurose and Ross (Computer Networks) details the basics of the HTTP protocol, with section 2.2.3 highlighting the HTTP message format for requests and responses.
  • Section 2.7 in Kurose and Ross (Computer Networks) demonstrates how to use Python for socket programming, with 2.7.2 highlighting the TCP protocol you will use.
  • You can find an extremely simple Python tutorial at http://www.sthurlow.com/python/

Introduction

Implementation.

  • What happens if you try to make a second connection to your server while it is still handling another connection? For example, make one telnet connection to your server, but don't issue a request yet. Make another telnet connection. If it succeeds, issue a GET request. Then go back to your original connection and issue a GET request. What happened? Why?
  • Note that we use the program's directory to implicitly specify where the web server should look for files. Does this guarantee that a malicious web client cannot access files outside of the web server's directory? If so, explain why. If not, give an example of a request a client could make to obtain an unauthorized file.

What to turn in

  • Your wwwserv.py file
  • An enscripted version of your wwwserv.py
  • requesting a short file from your server,
  • making an invalid request, and
  • requesting a non-existant file.
  • A transcript of your server starting and handling these requests
  • Your answers to the questions

Python Hints

Conditionals and looping, simple string operations, splitting a string on whitespace, reading files, acknowledgments.

Assignment 1: Writing a Thread-per-Request Web Client and Server

Assignment 1: JavaScript fundamentals

Due thu apr 20 11:59pm pt.

Submissions not accepted after Sat Apr 22 11:59pm PT .

Backstory: As you embark on your web development journey, you decide to set your sights on something we can all get behind: fixing Axess! And hey, those systems are probably so broken that we may as well start from scratch, right? But before you can take on course enrollments, you'll need a few building blocks first. Besides, as we come up on commencement, maybe you can build up your reputation as a reliable web developer by helping out with that.

This assignment will have you practice some fundamental JavaScript concepts and how to use them in the browser. You'll build a small app to simulate students declaring their major and graduating.

Learning goals

After completing this assignment, you will be able to

  • Write functions and classes in JavaScript that manipulate various types and data structures,
  • Create modules that import dependencies,
  • Create a small HTML page with form elements, and
  • Use JavaScript to respond to user events and read form controls.

Getting started

As with assignment 0, follow these steps to get started.

  • Download the starter code and extract the .zip file's contents.
  • Open your command line and navigate to the extracted assign1 directory.
  • Run npm install .
  • Run npm start to start the web server.
  • Open localhost:1930 in your web browser.

Deliverables: We've tried to use boxes like this one to highlight the specific tasks you will need to complete for the assignment. These boxes won't stand alone without the rest of the handout, but consider, for example, using them as a checklist to make sure you've done everything.

Part 1: Warmup exercises

The first part of the assignment consists of a few short warmup exercises, designed to give you practice with JavaScript data structures.

You will write your answers in warmups.js , which has already been included in index.html . We have provided a function testWarmups() , callable from the console, to check your answers.

Task 1a: Using the debugger

The first task will give you practice using the debugger.

  • To begin, please make sure you replace the TODO in the import line at the top of warmups.js with your SUNetID (login name, not number).
  • The function debugExercise calls checkAnswer , passing it a "secret code." Your task is to determine the correct code to pass. But since checkAnswer is being imported from debugme.js , located outside of your assign1 folder, you won't be able to modify it (in order to, for example, add a console.log ).
  • Use the debugger to look at the JavaScript code for checkAnswer . Then, call debugExercise from the console and stop the function while it is running so you can inspect the values of the relevant variables to determine what you must pass to it.
  • Once you have the secret code, replace the TODO in the argument to checkAnswer . Rerunning debugExercise should print a "Success!" message.
  • Finally, fill in the comment in debugExercise with a brief (1-2 sentence) explanation of your strategy: how did you enter the debugger, and where did you stop? How did you read the secret code?

Some notes for this task:

  • The list of files in the Sources tab is split up by where the files are located. You'll find debugme.js under web.stanford.edu .
  • The secret code is a short string of random characters, different for each student. The script that generates it uses some advanced JavaScript features, so we've tucked it away in another file. You may look at the file if you'd like, but it's not necessary (and probably won't help you get the answer).
  • This being the web and JavaScript, there are ways to "circumvent the process" and solve the task without the debugger. We ask that you avoid these unintended alternate strategies, both because we think the debugger is a valuable tool to have in your toolbox, and because we expect that solving the task using the debugger will be much easier. If, after following the process we've outlined, you want to think about how you might solve it a different way, feel free.

Task 1b: Working with data structures

For the rest of this assignment, you'll work with data for a few sample students and departments.

First, open data.js to have a look at the provided data. The file exports a single JavaScript Object with three entries:

  • students is an Array of Objects, each object representing a student. A student object contains their givenName , their surname , and their sunetid . (Note: These aren't the CAs' actual SUNetIDs.) You can assume that SUNetIDs will be unique across all students in the array.
  • depts is an Array of Objects. Each object contains information about a department: its name (like "Computer Science") and its code (like "CS").
  • units is an Object mapping student SUNetIDs (keys) to the number of units that student has completed (values). You may assume that there will be one entry in the object for each student in students .

This data object has been imported into warmups.js as the variable DATA . Once you have reviewed the data, fill in the functions in warmups.js , using DATA , as follows:

  • firstNSunets returns the SUNetIDs of the first n students ( n is a parameter to the function) in the students array. You can assume there are at least n students.
  • shortDeptCodes returns an Object whose keys are department names and whose values are their corresponding codes. But only include a department in the result if its code is exactly two characters long.
  • averageUnits returns the average number of units completed by all students in the data. You can assume there will be at least one student, and you don't need to round or truncate the result.

Each function should be relatively short and will involve some form of iteration. Once you have written these functions, you can use testWarmups (which is exposed to the console) to check that your answers match what we expect.

Note on style and style checking

To help identify some common style issues (and a few functionality issues too), we have includes a configuration file for ESLint .

If you are using VSCode and have installed the ESLint extension, these issues should be highlighted automatically as you code. (If you aren't seeing any highlights, you may have to restart VSCode after you do npm install .)

If you are using something else, or would like to check for lint errors manually, you can run npm run lint in your terminal (you'll have to do this in a different window than the one you ran npm start in).

Note that ESLint won't catch all (or indeed most) style issues. We will give you specific style feedback on your assignment through grading. But having a clean lint run is a good first step!

Part 2: Modeling students and departments

For the remainder of the assignment, you will work with the various other .js files in the public folder. All of these files are imported by index.js . We have included index.js in the provided HTML.

Your next task is to implement two JavaScript classes which we will use to model students and departments in our app.

Task 2a: Student class

Implement the Student class in student.js , and export it as the default (and only) export. An instance of Student will have the following properties (instance variables), which are all "public":

  • sunetid : The student's SUNetID
  • givenName : The student's given name
  • surname : The student's surname
  • dept : The name of the department the student is declared in (a string), or null if the student has not declared yet
  • unitsCompleted : The number of units the student has completed (a number)
  • isAlum : true if the student has graduated, false if not

An instance has the following methods (with corresponding signatures):

  • constructor(sunetid, givenName, surname) : Construct a new Student . The student's SUNetID, given name, and surname are as passed in. Students start undeclared, ungraduated, and with zero units completed.
  • fullName() : Return the student's full name, which is their given name, followed by a space, followed by their surname.
  • addUnits(units) : Increase the number of units the student has completed by the parameter units .
  • toString() : Return a string representing the student, which should be their given name, a space, their surname, another space, and their SUNetID in parentheses. (For example, "Michael Chang (mchang91)")
  • canGraduate() : Return a boolean indicating whether the student can graduate. A student can graduate if they have declared and have completed at least 180 units. If the student has already graduated, this method should throw an Error with a descriptive message.

Task 2b: Department class

Now write the Department class and export it as the default export in dept.js . An instance of Department has the following "public" properties:

  • name : The full name of the department
  • code : The department code
  • students : An array of the current (non-alum) students who have declared under this department

Implement the following methods:

  • constructor(name, code) : Construct a new department with the name and code passed in. Departments start with no current students.
  • toString() : Return the string representation of the department, which is just the department's name.
  • declare(student) : Declare the passed-in Student instance under this department, updating the student's and department's instance variables accordingly. If the student is already declared under this department, this method should return without doing anything. But if the student is already declared under a different department, this method should throw an Error with a descriptive error message.
  • graduate() : Check if each current student in the department can graduate; if they can, mark them as an alum and remove them from the list of current students. Return an array of the just-graduated Student instances.

Some notes on these tasks:

  • You may add additional instance variables and methods to these classes if you wish, but you are not required to.
  • It is a good practice to reuse existing functionality where possible. For example, notice how a Student 's toString contains their full name.
  • You may assume that a client of these classes will not modify the instance variables in a way that makes the instance inconsistent. For example, a client will not directly set a student's dept without going through declare .
  • You aren't required to do any error checking beyond what is described here.
  • Review the end of lecture 3 for the syntax for throwing Error s. Your errors should generate exceptions that can be caught and handled by the client of your class (which you will do in the next part).

Part 3: The App class

Finally, you'll put this app together by implementing the App class (in app.js ).

Task 3a: Console interface

An instance of the App class is constructed by index.js when the page loads. App has the following instance variables:

  • students : An Object mapping students' SUNetIDs (keys) to corresponding Student instances.
  • depts : An Object mapping department codes (keys) to corresponding Department instances.

The constructor has been started for you; you will add to it in the next task. First, implement the following methods:

  • First, reset the students and depts instance variables to be empty. This allows loadData to "reset" the app.
  • Populate the students map with new Student instances, using the students data.
  • Update the number of units each student has completed via the units data.
  • Populate the depts map with new Department instances, based on the passed-in data.
  • declare(sunetid, deptCode) : Takes a SUNetID and department code (both strings) and tries to declare that student under that department, then returns the (updated) Student instance. If the SUNetID or department code isn't known to the app, throw an Error with a descriptive message. (If calling declare on the Department causes an error, don't handle it here.)
  • graduate(deptCode) : Make the department specified by the passed-in code try to graduate its students, returning the list of graduates ( Student instances). If the department code doesn't match a known department, throw an Error with a descriptive message.

You will also need to add imports for Student and Department .

After completing these methods, you will be able to test your app from end to end:

  • The app instance is exposed to the console. You can inspect its instance variables and call its methods.
  • For example, you could call app.declare(“mchang91", "CS") or app.graduate(“BOGUS") . (Note that loadData is already called for you in index.js .)
  • The function testApp , exposed to the console, will attempt to test a variety of methods from part 2 and this task. If anything doesn't match, it will print out an error message. These tests aren't comprehensive, and we encourage you to add some more tests of your own.

Task 3b: User interaction on the page

Your final task of this assignment is to expose the declare and graduate methods you just wrote to a user of the web page:

  • Edit the HTML to add a form with two inputs, one for SUNetID and one for department code. These inputs should be labeled so they are identifiable, and make sure to give them id s so you can reference them in JavaScript.
  • Add two buttons to the form, one for "Declare" and one for "Graduate".
  • When the user types in a SUNetID and department code and clicks "Declare", call your app's declare method with the entered values.
  • If the declaration is successful, display an alert informing the user, including the student's name and the department name. For example, "Michael Chang (mchang91) declared Computer Science!"
  • If the declaration fails, display an alert with the error message. (Note: It's not enough for the error to be printed to the console, since users won't think to look there. You must catch the error and present it via alert .)
  • Similarly, implement the "Graduate" button. This button ignores the entered SUNetID. Upon success, display an alert listing the students who graduated. For example, Graduates: Neel Kishnani (neelk) Jason Chuen (jahchuen) (You can use \n to add a newline in alert messages.)

Some notes on this task:

Screenshot of form controls and buttons

  • You will need to add additional methods to App and are free to add instance variables as well. But you should mark them as "private" by prefixing them with an underscore (_).
  • Recall from lecture 4 that you can access the forms on a web page using document.forms , and you can reference the controls of a form using their id or a property of the form.
  • Remember that a <button>l; inside of a <form> defaults to having type="submit" , meaning it will refresh the page when clicked. You'll want to change its type to button to avoid this.
  • Don't forget to bind your event handlers! As seen in lecture 4, it is best practice to do this in the constructor (and this is preferred over creating functions on the fly.)

When you are finished, please remember to delete your node_modules folder , and then submit your assign2 folder to Paperless .

CSE 222: Computer Communications Networks

Home Syllabus Details Project Information Lecture Notes Assignments

Assignments

Assignment 1: a web server.

The goal of this project is to build a functional HTTP/1.0 server.  This assignment will teach you the basics of distributed programming, client/server structures, and issues in building high performance servers.  While the course lectures will focus on the concepts that enable network communication, it is also important to understand the structure of systems that make use of the global Internet.

This project should be done in teams of two.

Part 1: Build the Server (Due: Apr 18, 5 pm)

At a high level, a web server listens for connections on a socket (bound to a specific port on a host machine).  Clients connect to this socket and use a simple text-based protocol to retrieve files from the server.  For example, you might try the following command from a UNIX machine:

% telnet www.cs.ucsd.edu 80 GET /index.html HTTP/1.0\n \n

(type two carriage returns after the "GET" command).  This will return to you (on the command line) the html representing the "front page" of the UCSD computer science web page.

One of the key things to keep in mind in building your web server is that the server is translating relative filenames (such as index.html ) to absolute filenames in a local filesystem.  For example, you might decide to keep all the files for your server in ~student/cse222/server/files/ , which we call the root.  When your server gets a request for index.html , it will prepend the root to the specified file and determine if the file exists, and if the proper permissions are set on the file (typically the file has to be world readable).  If the file does not exist, a file not found error is returned.  If a file is present but the proper permissions are not set, a permission denied error is returned.  Otherwise, an HTTP OK message is returned along with the contents of a file.  How would your server support ".htaccess" files on a per-directory basis to limit the domains that are allowed access to a given directory?

You should also note that web servers typically translate "GET /" to "GET /index.html".  That is, index.html is assumed to be the filename if no explicit filename is present.  That is why the two URL's " http://www.cs.ucsd.edu " and " http://www.cs.ucsd.edu/index.html " return equivalent results.

When you type a URL into a web browser, it will retrieve the contents of the file.  If the file is of type text/html , it will parse the html for embedded links (such as images) and then make separate connections to the web server to retrieve the embedded files.  If a web page contains 4 images, a total of five separate connections will be made to the web server to retrieve the html and the four image files.  Note that the previous discussion assumes the HTTP/1.0 protocol which is what you will be supporting in this first assignment.

Next, add simple HTTP/1.1 support to your web server, consisting of persistent connections and pipelining of client requests to your web browser. You will also need to add some heuristic to your web server to determine when it will close a "persistent" connection. That is, after the results of a single request are returned (e.g., index.html), the server should by default leave the connection open for some period of time, allowing the client to reuse that connection to make subsequent requests. This timeout needs to be configured in the server and ideally should be dynamic based on the number of other active connections the server is currently supporting. That is, if the server is idle, it can afford to leave the connection open for a relatively long period of time. If the server is busy, it may not be able to afford to have an idle connection sitting around (consuming kernel/thread resources) for very long.

For this assignment, you will need to support enough of the HTTP protocol to allow an existing web browser (netscape or IE) to connect to your web server and retrieve the contents of the UCSD CS front page from your server.  (Of course, this will require that you copy the appropriate files to your server's document directory.)

At a high level, your web server will be structured something like the following:

Forever loop: Listen for connections     Accept new connection from incoming client     Parse HTTP/1.0 request     Ensure well-formed request (return error otherwise)     Determine if target file exists and if permissions are set properly (return error otherwise)     Transmit contents of file to connect (by performing reads on the file and writes on the socket)     Close the connection

You will have three main choices in how you structure your web server in the context of the above simple structure:

  • An event-driven architecture will keep a list of active connections and loop over them, performing a little bit of work on behalf of each connection.  For example, there might be a loop that first checks to see if any new connections are pending to the server (performing appropriate bookkeeping if so), and then it will loop overall all existing client connections and send a "block" of file data to each (e.g., 4096 bytes, or 8192 bytes, matching the granularity of disk block size).  This event-driven architecture has the primary advantage of avoiding any synchronization issues associated with a multi-threaded model (though synchronization effects should be limited in your simple web server) and avoids the performance overhead of context switching among a number of threads.

You may choose from C or C++ to build your web server but you must do it in a Unix-like environment.  You will want to become familiar with the interactions of the following system calls to build your system: socket(), select(), listen(), accept(), connect() .  We outline a number of resources below with additional information on these system calls.  A good book is also available on this topic.

Submission: Part 1 Assignment 1 submission guidelines

Part 2: Performance Evaluation (Due May 2, 11:59 pm)

Now that you have a functional web server, the second part of the project involves evaluating the performance of the system that you have built.  Build a synthetic client program (in C or C++) that connects to your server, retrieves a file in its entirety, and disconnects.  The goal of this load generator is to evaluate the performance of your server under various levels of offered load.  You will measure server performance in terms of throughput (requests/sec) and in terms of latency (average time to retrieve a file). Your synthetic load generator might be multi-threaded, with a different number of threads attempting to retrieve files as quickly as possible, or you may use a multi-process approach, where individual instances of your load generator start up, retrieve a file, and shut down.  You can control offered load by controlling the number of simultaneous threads/processes that are retrieving files from the server.  You should measure how long each request takes and keep track of this information for summary reporting (this will be used to generate average latency).  You should also measure the total number of requests satisfied in a given time period (this will be used to generate average throughput).

A principal aspect of this assignment is to compare the performance of your web server using HTTP/1.0 versus HTTP/1.1, especially given the behavior of TCP. There is significant overhead to establishing and tearing down TCP connections (though this is less noticeable in a LAN setting) and persistent connections avoids this issue to some extent.

Can you think of any instances where 1.1 will underperform 1.0?  A number of considerations affect the performance HTTP/1.0 versus 1.1.  Principally consider some of the pros and cons of using a connection per session versus using a connection per object.  Principally, the difference between the two comes down to the following:

  • However, all objects must be retrieved in serial in HTTP/1.1 meaning that some of the benefits of parallelism are lost.

Under what conditions would HTTP/1.1 underperform 1.0?  Also consider the effects of the bandwidth delay product, round trip times, and file sizes on this tradeoff.  For example, high round trip times exacerbate the negative effects of slow start (taking multiple rounds to send a file even if the bottleneck bandwidth would allow the entire file contents to be sent in a single round trip).

It will be important to run your web server and load generator on different machines.  It may be necessary to use multiple machines as load generators to saturate the server.  You will want to keep track of CPU load on both the load generator and the server machines to determine when each system component saturates (at least with respect to CPU load).

Profile your server code to get a rough idea of the relative cost of different aspects of server performance.  For different sized files, how much time is spent in establishing/tearing down connections versus transmitting files?  Use timing calls around important portions of your code to keep track of this time on a per-logical operation basis. What type of bandwidth does the web server deliver as a function of file size?

Try running your test for different periods of time to see how offered load and throughput changes with the duration of your experiment.

Also try running your test for different size files.  How does latency/throughput change with file size?

You may find it useful to use a scripting language, such as perl or python, to control the performance evaluation.

For extra credit, conduct your performance evaluation using different structures for your HTTP server.  For example, if you decided to build your server using a multi-threaded model, implement an alternate version that uses an event-based/single threaded approach for handling requests.  How does the performance characteristics of your server change with different system structure?

A very important aspect of your assignment will be your project report describing your system architecture, implementation, and high level design decisions.  For your performance evaluation, you should include a number of graphs describing the various aspects of system performance outlined above.  Make sure to clearly describe how you set up your experiments.  What kinds of machines did you run on?  What kind of network interconnected the machines?  How did you build your load generator and collect statistics?  How many times did you run each experiment to ensure statistical significance?  Ideally, you will include error bars to indicate standard deviation or 95% confidence levels.  Finally, your writeup should include explicit instructions on how to install, compile, and execute your code.

You should turn in an initial version of your writeup for the first part of the assignment and then add to it (with any necessary revisions) for the second part.  Your writeups are due with the assignments at the times specified above.

Submission: Part 2 Assignment 2 submission guidelines

We have collected a list of available resources to help you get started with various aspects of this assignment:

  • Multithreading in C++ and Java: http://www.devx.com/upload/free/features/vcdj/2000/05may00/dm0500/dm0500.asp

CS 431/531 Web Server Design

A course to develop a standard compliant http web server, assignment 1.

Due Date: 2022-10-04

Available Points: 20

Status Codes

  • 400 - Bad Request
  • 403 - Forbidden
  • 404 - Not Found
  • 500 - Internal Server Error
  • 501 - Not Implemented
  • 505 - HTTP Version Not Supported

Request Headers

  • Connection: close

Response Headers

  • Last-Modified
  • Content-Length
  • Content-Type
  • application/pdf
  • application/vnd.ms-powerpoint
  • application/vnd.ms-word
  • message/http
  • application/octet-stream (default MIME type)

Your Access Log

  • GET /.well-known/access.log HTTP/1.1
  • cf. RFC 8615
  • Typically not a good idea to expose your logs via the web server, but OK for this project
  • Implement as a virtual URI
  • Use Common Log Format
  • Server with Content-type: text/plain
  • Limited functionality - Points will be deducted for headers, response codes, etc. that are not explicitly defined in this assignment!

Submission and Evaluation

  • Extract sample test files tarball into your web server’s document root
  • Place your Dockerfile at the root of your repository (not inside of a nested folder)
  • Make your Dockerfile run your server on port 80 by default
  • Release your implementation with the a1 tag
  • Submissions will be evaluated using a variation of cs531a1 test suite from our testing service and some manual inspection of responses and source code (if necessary)
  • Tests will be performed based on the contents and structure of the a1-test folder of the sample test files

Step-by-Step Guide to Creating a Web Server

David Henegar

In this guide, you will learn how to set up a web server using socket programming and a few other tools in easy steps. By following this guide, you will be able to create a fully functional web server that can accept and process requests. You can also extend the functions further to do more complex operations.

Prerequisites

Before beginning this tutorial you should have a basic knowledge of following:

You should also have the following tools installed:

Step 1: Setting up the Socket

The first step is to set up the socket and establish a connection with the client. For this, we will use the socket module of Python.

Here is a sample code snippet for setting up the socket:

Step 2: Creating the HTML File

Once the connection is established, we will create an HTML file that will be the basis of the response. Create a file index.html and add the following content:

Step 3: Serving the HTML File

Now, let us serve the HTML file so that it can be accessed by the client. We will use the send method of the Python socket to send the HTML file to the client.

Here is a sample code snippet for sending the HTML file:

Step 4: Closing the Connection

Once we have sent the HTML file, we can close the connection with the client. For this, we use the close method of the Python socket.

Here is a sample code snippet for closing the connection:

Q1: What is socket programming?

Socket programming is a method of communication between two programs running on different computers over a network. It is an efficient way of transferring data between two programs.

Q2: How do I create a web server in Python?

You can create a web server in Python by using the socket module of Python. The socket library can be used to establish a connection with the client and send responses containing HTML, images, and other content. Additionally, Python libraries like Django, Flask, and Bottle can be used for creating web servers.

Q3: What is the structure of a basic HTML file?

A basic HTML file consists of a  tag which contains a  tag and a  tag. The  tag contains information about the HTML page, while the  tag contains the actual content of the HTML page.

Q4: What should I keep in mind while setting up the Python socket?

When setting up the Python socket, you should keep the following points in mind -

  • Get the local machine address and port number to bind the socket
  • Establish the connection using the socket.connect() method
  • Listen to incoming requests using the socket.listen() method
  • Send responses to the client using the socket.send() method
  • Close the connection using the socket.close() method

Q5: What are the advantages of socket programming?

The advantages of socket programming include its ability to facilitate communication between two applications running in different computers, its versatility in being able to work with different network protocols, and its efficient method of transferring data over a network. Additionally, it is a cost-effective method of communication as it does not require any additional hardware or software.

Additional Resources

Socket Programming in Python

HTMl Tutorial

Playing Audio Files: Don't Play this File Twice for Best Results

Troubleshooting template issues: resolving inaccessibility and non-existence errors in configured template resolvers, how to fix the no argument given error in form parameters, soling "_registercomponent(...): target container is not a dom element " error, guide to well-formed markup: ensuring proper document structure after the root element, troubleshooting guide: fixing pandoc document conversion error 43 fast & effectively, fixing 'target container is not a dom element' error: a guide for web developers, how does one create a static field by placing - comprehensive guide, what is mshta.exe microsoft (r) html application host - comprehensive guide, step-by-step guide to use microsoft (r) html application host.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Your link has expired.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Assignment #1 - Multi-threaded Web Proxy Server

Due by 11:59pm, Tuesday, September 26.

Assignment overview: In this assignment you are asked to build a multi-threaded Web proxy server that is capable of delivering Web content on behalf of a remote Web server. When a user's browser is configured to connect via a proxy server , her browser establishes a connection to the proxy server's machine and forwards its complete request to the proxy server rather than the "real" Web server. The proxy server accepts user's HTTP requests and forwards them to their final destination - essentially it introduces an extra "hop" between the user's browser (or the client) and the Web server. There are several reasons why people want to use a proxy server instead of connecting to the remote Web server directly: 1) users want to anonymize themselves from the Web server; 2) a corporation might want to monitor or restrict employees' Web surfing; 3) a proxy can be used to locally cache data in order to reduce the amount of global traffic.

Multi-threading is not crucial to the functionality of a Web proxy server, but it is important to allow the server to process multiple simultaneous requests in parallel, a must-have feature for a practical server. This is an individual assignment, so each person should turn in his/her own. Most kinds of communication among the students are encouraged except, of course, copying other people's code.

Requirements in detail: The proxy server acts as a HTTP server to client browsers while it acts as a HTTP client to the "real" Web server. The protocol specification for version 1.0 of HTTP is defined in RFC 1945 . This is not a long document among the protocol specifications, but it may well appear so for you. For your relief, you are asked to implement a very small part of the complete protocol, which will be explained below. We do try to be as specific as possible in this assignment description in order to reduce your need to refer to the lengthy protocol specification. But you should be prepared to do so occasionally.

A full HTTP-1.0 compliant Web server supports HEAD, POST, and GET methods. Your proxy server only needs to support GET method. To serve each request, we first need to parse the request line and headers sent by the client. Since we will only support GET method, we only care about Web page name in request line. The request line for the proxy server typically looks like this: GET http://www.foo.com/mumbo.html HTTP/1.0 ... ... The requested Web page name contains the Web server name www.foo.com and the requested file on that server /mumbo.html . In this case, your proxy server should make a TCP connection to Web server www.foo.com at the default port 80 and ask for file /mumbo.html by send the following request: GET /mumbo.html HTTP/1.0\r\n\r\n

After sending a request to the "real" Web server, a HTTP response including the requested file will be received at the proxy server. The proxy server should then forward the content to the client. There are three parts in a HTTP response message: the status line, the response headers, and the entity body. The status line and response headers are terminated by an empty line (or an extra "\r\n" ). In short, a HTTP response message may look like the following: HTTP/1.0 200 OK Server: Joe's Web proxy server Date: Thu Sep 12 17:52:40 EDT 2002 Content-length: 3814 Last Modified: Thu Sep 12 01:37:39 EDT 2002 Content-type: text/html ... ... <content of the main.html> The status line and most of the header fields should be forwarded to the client without modification. Note the Date and Last Modified are not important and you can choose not to send them back to the client.

The server should be able to handle multiple simultaneous service requests in parallel. This means that the Web proxy server is multi-threaded. In the main thread, the server listens at a fixed port. When it receives a TCP connection request, it sets up a TCP connection socket and services the request in a separate thread. You are asked NOT to set any timeout on each connection socket. This should be the default behavior.

Program skeleton: Here we provide a hint on what the program skeleton may look like. You are, however, not required to design your program this way. Main routine { Parse the command line input (server port number); Create a server socket listening on the specified port; For each incoming client socket connection { Spawn a worker thread to handle the connection; Loop back to wait for/handle the next connection; } } Worker thread routine { Read the request line and header fields until two consecutive new lines; (Note that a new line can be a single "\n" or a character pair "\r\n".) Examine the first line (request line); If the request method is not "GET" { Return an error HTTP response with the status code "HTTP_BAD_METHOD"; } Make TCP connection to the "real" Web server; Send over a HTTP request; Receive the server's response; Close the TCP connection to the server; Send the server's response back to the client; Close the connection socket to the client. }

Testing: If you develop your program at your home computer, it is imperative to test it in school network before turn-in. Below we provide some information about how to test your program.

As you are developing the code, you can configure a Web browser to use your proxy server for testing. For Internet Explorer 6.0, you can configure it in the following way: 1) Choose "Tools" in the Menu; 2) Click "Internet Options ..."; 3) Choose "Connections" Tab; 4) Click "LAN Settings ..."; 5) Choose "Proxy Server" and fill the server name as well as its port number. Make sure your proxy server is running and now all HTTP requests from your browser are served via the proxy server!

You can also test your server using raw telnet. If your proxy server runs at port 8080 of cycle1.csug.rochester.edu , you can do [yourself@foobar] telnet cycle1.csug.rochester.edu 8080<enter> GET http://www.google.com HTTP/1.0<enter> <enter> ... ... <response from your server, including status line, header, and the requested file> [yourself@foobar] You can also try this with the Web server directly, then you will need to specify the default port number 80. For instance, you can do [yourself@foobar] telnet www.google.com 80<enter> GET / HTTP/1.0<enter> <enter> ... ... [yourself@foobar]

Caching (extra credit work): Caching is a desirable feature at the proxy server. With caching, the proxy server stores the return data of past requests in local storage. If the new request matches a past one, the proxy server will directly return the cached data (in local storage) without actually contacting the remote Web server. This may save wide-area network bandwidth because the proxy server is usually close to the client machines while the "real" Web servers are often far away.

When you test the caching functionality in the proxy server, keep in mind that your Web browser also has a cache. So if you request the same file twice from the same browser, the browser cache would kick in first and the second request would not even reach the proxy server. A proper way to test the proxy server caching is to have two different browsers (with different browser caches) to access the same Web page.

Turn-in: You are asked to turn in your source files, a makefile if needed, and a README file. No matter what programming language you choose to use, your program should take a single parameter (its port number) on startup. You should also name your executable to be ProxyServer . If your program is written in Java, you should be able to launch your server using " java ProxyServer <port-number> ". If your program is written in C/C++, you should be able to launch your server using " ProxyServer <port-number> ".

The README file should be in plain text format. It should contain a description of your design. What is and what is not realized in your implementation. If your program requires any special compilation flag to build, you need to specify the full build command in the README file. You are strongly recommended to provide us a makefile.

We will provide a turn-in facility that you can turn in your assignment electronically. We will post the instructions on how to use it shortly.

  • 70%: properly forward Web pages from remote servers to browsers.
  • 20%: multi-threading that allows the server to service multiple client connections simultaneously.
  • 10%: a clear README file, clarity of your source code and completeness of your comments.
  • 10% extra credit: implement a caching scheme for the proxy server. Please explain your implementation in the README file.

Late turn-in policy: Late turn-ins will be accepted for up to three days, with 10% penalty for each late day. No turn-ins more than three-day late will be accepted.

IMAGES

  1. Solved Socket Programming Assignment 1: Web Server In this

    assignment 1 web server

  2. Assignment 1: Web Server In this assignment, you will

    assignment 1 web server

  3. Solved Assignment 1: Web Server In this assignment, you will

    assignment 1 web server

  4. Assignment 1 Web Server

    assignment 1 web server

  5. Solved Assignment 1: Web Server In this assignment, you will

    assignment 1 web server

  6. Socket Programming Assignment 1: Web Server In this

    assignment 1 web server

VIDEO

  1. WTL- Assignment No-1 Installation of Web Server- Tomcat

  2. Web Server Concepts and Examples

  3. Build a Basic Web Server with Node JS

  4. Building a webserver from scratch

  5. How The Web Works

  6. What are web servers and how do they work (with examples httpd and nodejs)

COMMENTS

  1. Socket Programming Assignment 1: Web Server

    Socket Programming Assignment 1: Web Server 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.

  2. PDF Socket Programming Assignment 1: Web Server

    Socket Programming Assignment 1: Web Server 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 assend and receive a HTTP packet. You will also learn some basics of HTTP header format.

  3. Web server and client

    Part 1: Web Server. You need to a develop a web server that handles one HTTP request at a time. Your web server needs to: Run on port 6789 by default, or on whatever port is given as the first command-line argument. Accept and parse the HTTP request. Get the requested file from the server's file system.

  4. Socket-Programming-Assignment-1-Web-Server/server.py at master ...

    Socket Programming Assignment 1: Web Server. Contribute to Liyang9898/Socket-Programming-Assignment-1-Web-Server development by creating an account on GitHub.

  5. Lab: Simple Web Server

    Introduction. In this lab you will implement and test a very simple web server using the hypertext transport protocol (HTTP), a text-based application-layer protocol. The basic outline is as follows. Your server will establish a listening socket and wait for connections in an infinite loop (so that it can serve as many as come in while it is ...

  6. CSE 124

    Assignment 1: A Web Server . The goal of this project is to build a functional HTTP/1.0 server. This assignment will teach you the basics of distributed programming, client/server structures, and issues in building high performance servers. While the course lectures will focus on the concepts that enable network communication, it is also ...

  7. Programming Assignment 1: Building a Multi-Threaded Web Server

    Programming Assignment 1: Building a Multi-Threaded Web Server. ... The final piece of code needed to complete the Web server is a method that will examine the extension of a file name and return a string that represents it's MIME type. If the file extension is unknown, ...

  8. Lab Assignment 1: A Web Server

    Lab Assignment 1: A Web Server. Assigned: February 6 Due date: February 18. Introduction. The first programming project in 6.033 is meant to prepare you for the next two projects by acquainting you with the tools of UNIX programming and especially network programming. Unlike the other labs, we will start you off with some code for setting up ...

  9. Assignment 1: Writing a Thread-per-Request Web Client and Server

    Assignment 1: Writing a Thread-per-Request Web Client and Server. The purpose of this assignment is to acquaint you with using the ACE C++ toolkit to perform network IPC between two host machines. We will actually be writing two programs: (1) a simple web client and (2) a simple web server. In brackets are some hints about what kinds of ACE ...

  10. PDF Programming Assignment 1: Socket Programming Due Date Goal

    In this assignment you will be asked to implement an HTTP client and server running a simplified ... To get the FULL CREDIT for the Web client and Web server: 1. On Client side, the client should obtain the entire html file from the server it is talk to, when its HTTP request succeeds. 2. On Server side, the entire TMDG.html test file can be ...

  11. PDF Lab 1: Web Server

    1. Currently, the Web server reads the entire file into memory before sending it. That's an inefficient approach if the file is large, and if the file is really large the server will break. Fix the server to read and send in small chunks (4K-8K is a good size). 2. Currently, the Web server handles only one HTTP request at a time.

  12. Assignment 1: JavaScript fundamentals

    Getting started. As with assignment 0, follow these steps to get started. Download the starter code and extract the .zip file's contents. Open your command line and navigate to the extracted assign1 directory. Run npm install. Run npm start to start the web server. Open localhost:1930 in your web browser.

  13. CSE 222 Assignments

    Assignment 1: A Web Server. The goal of this project is to build a functional HTTP/1.0 server. This assignment will teach you the basics of distributed programming, client/server structures, and issues in building high performance servers. While the course lectures will focus on the concepts that enable network communication, it is also ...

  14. Assignment 1

    A course to develop a standard compliant HTTP web server Home Syllabus Lectures Assignments Tester Discussions Assignment 1. Due Date: 2022-10-04 Available Points: 20 A web server with a limited set of methods, status codes, headers, MIME types, and the access log.

  15. PDF Socket Programming Assignment 1: Multi-Threaded Web Server ECE 156

    1 Socket Programming Assignment 1: Multi-Threaded Web Server ECE 156 September 19, 2006 Please read Sections 2.7-2.9 from the textbook to get an introduction to socket programming. In this programming assignment, you will use Java to develop a multi-threaded web server that can accept multiple requests in parallel.

  16. Programming Assignment 1 reference Python

    Socket Programming Assignment 1 : Web Server. 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.

  17. Socket Programming Assignment 1: Web Server (Resolved)

    Step 1: Setting up the Socket. The first step is to set up the socket and establish a connection with the client. For this, we will use the socket module of Python. Here is a sample code snippet for setting up the socket: import socket. # create a new socket. s = socket.socket()

  18. Solved Socket Programming Assignment 1: Web Server In this

    Computer Science questions and answers. Socket Programming Assignment 1: Web Server 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.

  19. Socket-Programming-Assignment-1-Web-Server/README.md at master ...

    Socket Programming Assignment 1: Web Server 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.

  20. python

    Currently doing an assignment in which we are programming sockets in python and thus creating a web server when the webserver.py code is executed.The code should then display HTTP headers and other

  21. Web Server

    Socket Programming Assignment 1: Web Server 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.

  22. PDF Programming Assignment 1

    Programming Assignment 1 | An HTTP Proxy Server Due: October 8, 2015 A web proxy is a program that acts as an intermediary between a web client (browser) and a web server. A user con gures a browser to use a proxy by entering the Internet address or domain name and port number for the proxy server into one of the browser's preference dialogs.

  23. Assignment #1

    Assignment #1 - Multi-threaded Web Proxy Server . Due by 11:59pm, Tuesday, September 26. Assignment overview: ... There are several reasons why people want to use a proxy server instead of connecting to the remote Web server directly: 1) users want to anonymize themselves from the Web server; 2) a corporation might want to monitor or restrict ...