Operating Systems Recitation 9, May 19-20, 2002. Iterative server Handle one connection request at a time. Connection requests stored in queue associated.

Slides:



Advertisements
Similar presentations
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Advertisements

Programming with TCP – I
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
COEN 445 Communication Networks and Protocols Lab 4
1 Processes Professor Jennifer Rexford
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
Page: 1 Director 1.0 TECHNION Department of Computer Science The Computer Communication Lab (236340) Summer 2002 Submitted by: David Schwartz Idan Zak.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Programming project #4 1 CS502 Spring 2006 Programming Project #4 Web Server CS-502 Operating Systems Spring 2006.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Concurrent vs. iterative servers
Operating Systems Recitation 11, June 9-10, 2002.
CS-3103 & CS-502, Summer 2006 Programming Project #31 Programming Project #3 Web Server CS-3103 & CS-502 Operating Systems.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
ECE 4110 – Internetwork Programming Client-Server Model.
Assignment 3 A Client/Server Application: Chatroom.
Elementary TCP Sockets
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Operating Systems Recitation 1, March th, 2002.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
CS162B: Pipes Jacob T. Chan. Pipes  These allow output of one process to be the input of another process  One of the oldest and most basic forms of.
Remote Shell CS230 Project #4 Assigned : Due date :
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
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.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Berkeley Socket Abstraction
CSCI 330 UNIX and Network Programming
UNIX Sockets Outline UNIX sockets CS 640.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
COMP2322 Lab 4 Socket Programming Toby Lam March 2, 2016.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CLIENT (Browser) socket accept C1 C2 recv C2 recv send C2 send end_thread recv C3 send bind connect Web Server Proxy recv close C3 close C2 end_thread.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
COMP2322 Lab 4 Socket Programming
Assignment 3 A Client/Server Application: Chatroom
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Operating Systems Review ENCE 360.
Sockets and Beginning Network Programming
Concurrent vs. iterative servers
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Transport layer API: Socket Programming
Advanced Network Programming spring 2007
Issues in Client/Server Programming
TA: Donghyun (David) Kim
Jan Ecs152b Behrooz Khorashadi
Server-side Programming CSE 333 Autumn 2018
Server-side Programming CSE 333 Summer 2018
Server-side Programming CSE 333 Winter 2019
Presentation transcript:

Operating Systems Recitation 9, May 19-20, 2002

Iterative server Handle one connection request at a time. Connection requests stored in queue associated with socket (avoid loosing them) server server application thread operating system socket for connection requests Q socket for individual connection

Concurrent server Handle multiple connection requests at a time. master server application thread operating system socket for connection requests Q sockets for individual connections slave

Using socket calls client side socket connect send recv closesocket server side socket bind listen accept recv send closesocket

bind Specifies the local address for a socket; well-known port at which server will wait for connections. int bind(int socket, struct sockaddr* local_addr, int local_addr_len);

listen OS creates queue of connection requests: hold new connection requests that arrive while server is busy handling a previous request; separate queue (initially empty) for each socket. Inserts connection requests arriving from clients. When server asks to retrieve an incoming connection request from socket, the OS returns the next request from queue. If queue is full when connection request arrives then it’s rejected.

listen Server calls listen to place a socket in passive mode and make it ready to accept incoming connections. Tells the OS to enqueue connection requests for a socket Input: –socket descriptor –size of the queue int listen(int socket, int queue_size);

accept Extracts the next incoming connection request. If connection request queue is not empty, accept returns immediately, otherwise system blocks the server until a client forms a connection. Before accept, a request ties up the socket that is bound to well-known port. Accept re- routes it to a new socket allowing original socket to receive additional clients.

accept All the different sockets created by accept share the same port on the server side. client A sd=3 IP client B sd=3 IP host A host B port 1234 port 5678 server process sd=4 IP well-known port sd=5 sd=3 src=other

accept Input: –descriptor of a socket (that server has created and bound to a specific port with wildcard foreign destination) from which a connection should be accepted. Output (when connection request arrives): –address structure of client that formed the connection and its length. –descriptor of new socket. Server uses each new socket to transfer data for each new connection, and original socket to accept additional connection requests. int accept(int socket, struct sockaddr* client_addr, int* client_addr_len);

Exercise description Concurrent server, implemented by forking a child process to handle each connection request. HTTP server providing dynamic content: client requests that server run a program; server runs program and returns output to client.

Exercise description socket bind listen loop accept fork and child handles connection child forks & it’s child executes program

Exercise description: server argument Initial (main) program argument: port number that server binds to (above 1024 otherwise permission denied).

Exercise description: server’s reply Server runs a program as requested by a client and sends back: –status –output length –output type –output Sending the output length before the output itself requires the server to use a buffer to store the output.

Exercise description: server’s reply Format: HTTP/ OK Content-Length: 29 Content-Type: text/plain data Status: 200 OK, if program run is successful; 300 ERROR, if program doesn’t exist or execv fails. Actual length of program output. Each line ends with \r\n

Pipe Half-duplex Used only between processes that have a common ancestor. #include int pipe(int filedes[2]); Returns 0 if OK, -1 on error filedes[0] is open for reading, filedes[1] for writing: output of filedes[1] is the input of filedes[0].

Using a pipe between parent and child Pipe created by a process. Process calls fork. Pipe is used between parent and child in one direction. parent fd[0] fd[1] pipe kernel child fork fd[0] fd[1]

Exercise description: reading from standard output using a pipe & dup2 child pipe fork parentchild close(pipefd[1])close(pipefd[0]) read(pipefd[0],buf,size)dup2(pipefd[1],1) execv standard output

Duplicating an existing file descriptor #include int dup(int filedes); int dup2(int filedes, int filedes2); Returns new file descriptor if OK, -1 on error.

Exercise description Server replies only to GET requests from clients, receiving an entire GET request from client (message ends with \r\n\r\n) Parses client requests in the format: GET HTTP/1.0\r\nhttp://nova.math.tau.ac.il:2000/date+-u The server prints on screen all the HTTP requests it receives, from which you can tell the format of the browser request. program to run program arguments delimited with + portmachine running the server

Exercise description: server tests Using a commercial web browser (IE), check your server, printout the results of two requests: and verify that the servers directory appears in the browser. and verify that you receive an updated date each time you refresh the browser. Copy the programs you run, such as date and ls, from /bin to the servers directory. Use the first four digits (after 0) of your ID number as the port.

Exercise description You can incrementally implement the server in several steps, testing each one: 1.Iteratively handle each connection request, ignoring the URL and sending a constant message to the client, with the proper header. 2.Concurrency handle each client connection request by a new process. 3.Parse the URL and execute the requested program, replying to the client.

Exercise submission Chapter 7.8 in Toledo’s book, pages Submission: Monday, June 17 th. Software Directory: ~username/os02b/ex-serve Files: ex-serve.c Permissions: chmod ugo+rx (to above) Hardcopy name, ID, login, CID ex-serve.c printout result of the two requests from web browser. submit in 281, Nir Neumark, Environment: Unix, Linux

Exercise notes You can use the functions recv/send or read/write (the latter receiving three arguments instead of four).

References Operating Systems, Sivan Toledo, Akademon, Internetworking with TCP/IP, Vol 3: client- server programming and applications, Douglas Comer & David Stevens, Prentice-Hall, Advanced programming in the Unix environment, Richard Stevens, Addison- Wesley, Example program on course webpage.