web engineering
play

Web Engineering 1. Architecture 2. Web Server Prof. Dr. Dr. h.c. - PowerPoint PPT Presentation

Table of Content Web Engineering 1. Architecture 2. Web Server Prof. Dr. Dr. h.c. mult. Gerhard Krger, Albrecht Schmidt 3. Web Client Universitt Karlsruhe Fakultt fr Informatik 4. Performance and Efficiency Institut fr Telematik


  1. Table of Content Web Engineering 1. Architecture 2. Web Server Prof. Dr. Dr. h.c. mult. Gerhard Krüger, Albrecht Schmidt 3. Web Client Universität Karlsruhe Fakultät für Informatik 4. Performance and Efficiency Institut für Telematik Wintersemester 2000/2001 Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page1 Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page3 How Does a Web Server Look Like? http://www.ibm.com Web Engineering Chapter 4: Architecture and Platform Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page2 Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page4

  2. How Does a Web Server Look Like? How Does a Web Server Look Like? http://www.sony.de http://www. earthcam .com/Solutions/ether.html http://www.dell.de http://www.axis.com/products/cam_2100/ Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page5 Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page7 How Does a Web Server Look Like? How Does a Web Server Look Like? http://www.palm.com / http://www.brodel.de/ http://www.handspring.com Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page6 Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page8

  3. How Does a Web Server Look Like? How Does a Web Server Look Like? http://world.std.com/~fwhite/ace/ http://world.std.com/~fwhite/ace/ http://www.margherita2000.com/ U Mass Hewlett Packard WebACE http://www-ccs.cs.umass.edu/~shri/iPic.html http://www.ibutton .com/TINI/ http://www.mycal.net/wsweb/ Prof. Dr. Dr. h.c. mult. Ger hard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page9 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page11 Common Properties of Web Servers How Does a Web Server Look Like? � Communication http://wearables.stanford.edu/ � e.g. ethernet, modem, serial line, GSM � permanent line � connection on demand � server initiated � client initiated � communicates using the HTTP-Protocol � accepts requests � sends replies � has access to resources � e.g. HTML, images, etc. � potentially manipulation of resources, side effects Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page10 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page12

  4. Web Server – Functional Units Single Thread/Process Server � waiting for an HTTP request Server-Loop: � server socket � wait for connection request � accept connection � extract resource name from request (e.g. path and file name) � analyzing of HTTP Request � access resource (e.g. read file from file system) � parser � send HTTP-Header � send resource (e.g. sent byte stream) � process request � close connection � access to file system or resources Goto Server-Loop � delegation to other system � answer with HTTP Reply � generate HTTP-header � send resource to client Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page13 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page15 Server - Basics Minimal Web Server in C I #include <stdio.h> � connection oriented transport system #include <sys/types.h> #include <sys/socket.h> � e.g. TCP/IP #include <strings.h> #include <netinet/in.h> #include <sys/stat.h> � iterative server #include <fcntl.h> � One request after another #define SERVER_PORT 8080 /* Server Port */ #define TRUE 1 � no concurrency add_header(char *ret) { � concurrent server strcat(ret, "Server: TecO_Mini Server(WebE/01)\n"); strcat(ret, "Content Type: text/html\n\n"); � multi process server } � new process per request (e.g. fork() ) main() { � multi threaded server int sd, nsd; /* socket descriptors */ � new thread per request (e.g. new_thread.run() ) struct sockaddr_in server; /* address for socket structur */ char buf[1024], ret[1024]; /* buffer for request and reply*/ � thread pool char *method, *filename; � fixed number of threads char *cursor; int read_bytes,fd; � dispatcher/worker-model int server_port=SERVER_PORT; Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page14 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page16

  5. Minimal Web Server in C II Minimal Web Server in C IV sd = socket(AF_INET, SOCK_STREAM, 0); /* create socket */ /* if no file, path is given read index.html */ if ((strlen(filename)==0)||(cursor[-1]=='/')) /* put addresse in structur */ strcat(filename,"index.html"); server.sin_family = AF_INET; /* Internet */ server.sin_addr.s_addr = htonl(INADDR_ANY); /* all addresses */ /* file name given */ server.sin_port = htons(server_port); /* Server Port */ printf("asks for file %s\n", filename); /* bind socket to address */ fd=open(filename,O_RDONLY,0); while(bind(sd, (struct sockaddr *) & server, sizeof(server))!=0) if(fd==-1) { { printf("Port %d is already bound, trying next\n",server_port); sprintf(ret, "HTTP/1.0 404 ERROR\n"); server.sin_port = htons(++server_port); /* Server Port */ add_header(ret); } strcat(ret, "<h1>File \n"); strcat(ret, filename); listen(sd, 5); /* wait for request */ strcat(ret, " not Found</h1>\n"); printf("Wait for Requests on port %i\n", server_port); write(nsd, ret, strlen(ret)); /* sent error 404 */ } Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page17 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page19 Minimal Web Server in C III Minimal Web Server in C V while (TRUE) { /* loop for ever */ /* accept requests */ nsd = accept(sd, (struct sockaddr *) 0, (int *) 0); else bzero(buf, sizeof(buf)); /* clear buffer */ { read(nsd,buf,sizeof(buf)); /* read request */ sprintf(ret, "HTTP/1.0 200 OK\n"); add_header(ret); write(nsd, ret, strlen(ret)); /* send header */ /* get the file name – pointers are cool ;-) */ /* no security concerns ... */ while((read_bytes=read(fd,ret,sizeof(ret)))!=0) filename=&buf[5]; { write(nsd, ret, read_bytes); /* send buffer */ cursor=filename; } while(!isspace(*cursor)) } { cursor++; close(nsd); /* close connection */ } printf(" - Requests handled!\n"); *cursor='\0'; } } see: http://www.teco.uni-karlsruhe.de/lehre/webe/unterlagen/webserver _in_c.pdf Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page18 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page20

  6. Multi Thread/Process Server Small Web Server in Java II // set the port to listen on try { Server-Loop: thePort = Integer.parseInt(args[1]); if ( thePort < 0 || thePort > 65535) thePort = 80; � wait for connection request } catch (Exception e) { � accept connection thePort = 80; } � create Thread/Process try { Goto Server-Loop ss = new ServerSocket(thePort); System.out.println("Accepting connections on port " + ss.getLocalPort()); System.out.println("Document Root:" + docroot); Thread/Process: while (true) { jhttp j = new jhttp(ss.accept()); j.start(); � extract resource name from request (e.g. path and file name) } } � access resource (e.g. read file from file system) catch (IOException e) { System.err.println("Server aborted prematurely"); � send HTTP-Header } � send resource (e.g. sent byte stream) } � close connection � terminate Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page21 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page23 Small Web Server in Java III Small Web Server in Java I public void run() { import java.net.*; String method; import java.io.*; String ct; import java.util.*; String version = ""; public class jhttp extends Thread { File theFile; Socket theConnection; try { static File docroot; static String indexfile = "index.html"; PrintStream os = new PrintStream(theConnection.getOutputStream()); DataInputStream is = new DataInputStream (theConnection.getInputStream()); public jhttp(Socket s) { String get = is.readLine(); theConnection = s; StringTokenizer st = new StringTokenizer (get); } method = st.nextToken(); public static void main(String[] args) { if (method.equals("GET")) { String file = st.nextToken (); int thePort; if (file.endsWith("/")) file += indexfile; ServerSocket ss; ct = guessContentTypeFromName(file); // get the Document root if (st.hasMoreTokens()) { try { version = st.nextToken(); docroot = new File(args[0]); } } // loop through the rest of the input lines catch (Exception e) { docroot = new File("."); } while ((get = is.readLine()) != null) { if (get.trim().equals("")) break; } Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page22 Prof. Dr. Dr. h.c. mult. Ge rhard Krüger, Albrecht Schmidt: Web Engineering, WS00/01 page24

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend