Building Your Very Own Web Server

Slides:



Advertisements
Similar presentations
Fun Fun Project One1 Building Your Very Own Web Server.
Advertisements

HTTP HyperText Transfer Protocol. HTTP Uses TCP as its underlying transport protocol Uses port 80 Stateless protocol (i.e. HTTP Server maintains no information.
Fun Fun Project One1 Building Your Very Own Web Server.
Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley, July.
Client, Server, HTTP, IP Address, Domain Name. Client-Server Model Client Bob Yahoo Server yahoo.com/finance.html A text file named finance.html.
Lecture 4 Web browsers, servers and HTTP Boriana Koleva Room: C54
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
Web Architecture Dr. Frank McCown Intro to Web Science Harding University This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike.
FTP (File Transfer Protocol) & Telnet
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
Rensselaer Polytechnic Institute Shivkumar Kalvanaraman, Biplab Sikdar 1 The Web: the http protocol http: hypertext transfer protocol Web’s application.
Copyright (c) 2010, Dr. Kuanchin Chen1 The Client-Server Architecture of the WWW Dr. Kuanchin Chen.
ASHIMA KALRA IMPORTANT TERMS.  WWW WWW  URL URL  HTTP PROTOCOL HTTP PROTOCOL  PROXIES PROXIES.
Web Server Design Week 8 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 3/3/10.
CIS679: Lecture 13 r Review of Last Lecture r More on HTTP.
CSx760 Computer Networks1 HTTP. CSx760 Computer Networks2 The Web: Some Jargon r Web page: m consists of “objects” m addressed by a URL r Most Web pages.
1-1 HTTP request message GET /somedir/page.html HTTP/1.1 Host: User-agent: Mozilla/4.0 Connection: close Accept-language:fr request.
WEB SERVER Mark Kimmet Shana Blair. The Project Web Server Application  Receives request for web pages or images from a client browser via the internet.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
Web Services. 2 Internet Collection of physically interconnected computers. Messages decomposed into packets. Packets transmitted from source to destination.
Overview of Servlets and JSP
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
Week 11: Application Layer 1 Web and HTTP r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Web page consists.
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
Network Applications: HTTP/1.0
What’s Really Happening
Data Communication EDA344, DIT420 Description of Lab 1 and Optional Programming HTTP Assignment Aras Atalar Prajith R G.
Distributed Control and Measurement via the Internet
Application Layer Dr. Adil Yousif Lecture 2 CS.
Hypertext Transfer Protocol
Block 5: An application layer protocol: HTTP
Building Web Apps with Servlets
Web Basics: HTML and HTTP
HTTP – An overview.
The Hypertext Transfer Protocol
How does it work ?.
1993 version of Mosaic browser.
Web Server Design Week 10 Old Dominion University
Computing with C# and the .NET Framework
COMP2322 Lab 2 HTTP Steven Lee Feb. 8, 2017.
Internet transport protocols services
Networking Applications
Debugging Your Website with Fiddler and Chrome Developer Tools
TCP/IP Networking An Example
Application HTTP.
Uniform Resource Locators
The Internet and HTTP and DNS Examples
HTTP Hypertext Transfer Protocol
CSE 461 HTTP and the Web.
HTTP Request Method URL Protocol Version GET /index.html HTTP/1.1
Uniform Resource Locators (URLs)
TCP/IP Protocol Suite: Review
HyperText Transfer Protocol
Hypertext Transfer Protocol (HTTP)
Web Server Design Week 8 Old Dominion University
William Stallings Data and Computer Communications
World Wide Web Uniform Resource Locator hostname [:port]/path
CS3220 Web and Internet Programming Handling HTTP Requests
Exam Review Quiz game.
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
The Application Layer: HTTP
Uniform Resource Locators
Application Layer Part 1
Traditional Internet Applications
HTTP Hypertext Transfer Protocol
Uniform Resource Locators (URLs)
CSCI-351 Data communication and Networks
Old Dominion University Department of Computer Science
Presentation transcript:

Building Your Very Own Web Server Fun Fun Project One Building Your Very Own Web Server Fun Fun Project One

What is a Web Server? Program that understands the HTTP protocol and generates appropriate responses Clients “connect” to the machine Clients send a “request” Server reads request, generates “response” Client interprets response appropriately Fun Fun Project One

A Simplified Web Server Client asks for file Server finds appropriate file Server sends back a response header followed by the requested file’s data Server closes connection Fun Fun Project One

What Does “Connect” Mean? For all practical purposes, it looks like there’s data available via a file descriptor Stream of bytes Can be treated like any other file descriptor Not a FILE * (like stdio, stderr) Must use read() and write() system calls Fun Fun Project One

How Do You Identify Machines Domain names/IP address and ports http://www.cs.princeton.edu implies a machine named www.cs.princeton.edu and a default port of 80 http://127.0.0.1:8080/index.html Refers to local box (127.0.0.1 is me) Port # is 8080 (used for this project) File is named index.html Fun Fun Project One

How Do You Identify Files? File name is specified in Request Message Server maps that name to a real file Mapping can be done in whichever way server wants For example, /~vivek/index.html is actually /n/fs/fac/vivek/public_html/index.html In your web server, you can choose your own Fun Fun Project One

What’s In A Request Message? GET /index.html HTTP/1.0\r\n Connection: Keep-Alive\r\n User-Agent: Mozilla/4.72 [en] (X11..)\r\n Host: 127.0.0.1:31415\r\n Accept: image/gif, image/jpeg, */*\r\n Accept-Encoding: gzip\r\n Accept-Language: en\r\n Accept-Charset: iso-8859-1,*,utf-8\r\n \r\n Fun Fun Project One

What Do You Care About? GET /index.html HTTP/1.0 In particular, just index.html Assume “/” means “/index.html” Fun Fun Project One

What Could They Want? An honest-to-goodness file (me.jpg) An indirect request for such a file (such as “/” meaning index.html) An implied directory with index (/home/vivek instead of /home/vivek/) Just a directory listing A query (we don’t care about these) An invalid/nonexistent file Fun Fun Project One

What’s In A Response Message? HTTP/1.0 200 OK\r\n Date: blah-blah-blah\r\n Server: blah-blah-blah\r\n Content-Type: important\r\n Content-Length: 12345\r\n Last-Modified: blah-blah-blah\r\n \r\n Raw data Fun Fun Project One

What’s a Minimal Response? HTTP/1.0 200 OK\r\n Content-Type: stuff\r\n \r\n Data HTTP/1.0 302 Moved\r\n Location: newurl\r\n HTTP/1.0 404 Not Found\r\n \r\n But also Connection: close\r\n Content-Length: yyy\r\n Fun Fun Project One

Response when… File exists? Send it Directory without “/” suffix? Redirect Directory with index.html? Send it Directory with no index.html? List it For each list entry, add “/” if needed Failure(Not Found)? Send 404 Bad Request? Send 400 Fun Fun Project One

How to Test Your Server? Use a browser(Netscape/IE) Use “wget” Support HTTP protocol http://www.gnu.org/manual/wget create directory hierarchy for retrieving Include some big images Fun Fun Project One

More Test Cases What if Request Message is not send/received in one packet… The server must read all the Request Messages before it gives any response message Remember the double carriage return and line feed? Your web server must consider this! I’ll distribute more test programs later on, check http://www.cs.princeton.edu/~yongwang/cos318 Fun Fun Project One

What is Content-Type? text/html image/gif image/jpeg (Other types not needed for project 1.) Fun Fun Project One

Need more info? HTTP 1.1 Specification – RFC2068 HTTP 1.0 – RFC 1945 man pages man man man –k blah read( ), write( ), open( ), close( ) Fun Fun Project One

Why open instead of fopen? Compare fopen, fread, etc., with open, read, etc We’re dealing with functions closer to the OS – easier to use in some cases Fun Fun Project One

What’s a File Descriptor? Sort of like a FILE * It’s an integer provided by OS Used to represent a stream of bytes Can represent file or network connection Behavior is slightly different Especially when reading/writing network Fun Fun Project One

General Steps Setup, and then Get next connection If file, read from disk If directory, generate listing Send all to client Close connection, wait for next one(nonpersistent connection) Fun Fun Project One

What Am I Given? Setup function Accept function File type function Makes server available for connections Accept function Gets a connection from a client File type function Tells you what kind of file, if it exists Tells you how many bytes if a regular file Directory listing functions Gives you the file names one at a time Fun Fun Project One

Help! I’m Lost! Don’t know HTML? Use Netscape composer to see what to do View page source for various pages Do “telnet www.domain.com 80” and issue the GET manually (need to add “Host: www.domain.com” header) Ask Fun Fun Project One

Why Are We Doing This? Infrastructure for future projects Some OS/Networking interaction It’s fun, and not too bad Fun Fun Project One

Wrap Up Thanks! Q&A session next week! Office Hour: Wed 4:30-5:30 Fun Fun Project One