Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

CS 4700 / CS 5700 Network Fundamentals
Programming with TCP – I
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
Computer Networks Sockets. Sockets and the OS F An end-point for Internet connection –What the application “plugs into” –OS provides Application Programming.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Advanced Sockets Amit Mondal TA, Intro to Networking Jan 22, 2009 Recital 3 Introduction to Networking Instructor: Prof. Aleksandar Kuzmanovic.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Sockets and concurrency Spring 2010, Recitation 3 Your Awesome TAs.
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
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.
© 2007 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.1 Computer Networks and Internets with Internet Applications, 4e By Douglas.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
Concurrent vs. iterative servers
SOCKETS Lecture #3. The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in Developed at UC Berkeley Objective: to transport.
Introduction to Project 1 Web Client and Server Jan 2006.
CSTP FS97CS490D (cotter)1 Sockets Programming in UNIX References: Internetworking with TCP/IP Vol III - BSD version UNIX Network Programming - W. Richard.
An Introduction to Internetworking. Algorithm for client-server communication with UDP (connectionless) A SERVER A CLIENT Create a server-socket (listener)and.
Lecture 8 UDP Sockets & I/O Multiplexing
1 Sockets Programming in Linux References: Internetworking with TCP/IP Vol III - Linux version UNIX Network Programming - W. Richard Stevens.
Tutorial on Socket Programming Data types and structures for writing client- server programs.
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
Fall 2000Datacom 11 Socket Programming Review Examples: Client and Server-Diagnostics UDP versus TCP Echo.
Elementary TCP Sockets
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
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 9, May 19-20, Iterative server Handle one connection request at a time. Connection requests stored in queue associated.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
1 Server Design Discuss Design issues for Servers Review Server Creation in Windows.
Client-Server Applications Approx. text coverage: Chap. 21, Vol III.
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS A: Windows Networking A.2. Windows Sockets.
1 Example Servers Pt 1 Objective: To discuss key aspects of various server implementations.
1 COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
1 I/O Multiplexing We often need to be able to monitor multiple descriptors:We often need to be able to monitor multiple descriptors: –a generic TCP client.
CSCE 515: Computer Network Programming Select Wenyuan Xu Department of Computer Science and Engineering.
Advanced Sockets API-II Vinayak Jagtap
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Example Servers Pt 2 Objective: To discuss key aspects of various server implementations.
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.
Socket Programming Lab 1 1CS Computer Networks.
Project 2: Socket Programming. Overview Sockets Working with sockets Client-Server example Project 1 Hints.
Cs423-cotter1 Concurrency Issues in Client/Server Applications Chapters 15,16, 28.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
PA3: Improving Performance with I/O Multiplexing Part 1-1: Nov. 7, Part 1-2: Nov. 10 Part 2-1: Nov. 17, Part 2-2: Nov.20.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Multimedia Retrieval Architecture Electrical Communication Engineering, Indian Institute of Science, Bangalore – , India Multimedia Retrieval Architecture.
Client-Server Programming and Applications. References Douglas Comer, David Stevens, “Internetworking with TCP/IP: Client-Server Programming and Applications”,
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
More Project 1 and HW 1 stuff! Athula Balachandran Wolfgang Richter
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Concurrent vs. iterative servers
Review: TCP Client-Server Interaction
TCP Sockets Programming
Socket Programming.
An Introduction to Internetworking
I/O Multiplexing We often need to be able to monitor multiple descriptors: a generic TCP client (like telnet) need to be able to handle unexpected situations,
Presentation transcript:

Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)

INTRODUCTION Last time: Concurrent Connection-Oriented server - echo server - that supports multiple clients at the same time using multiple processes Today: similar echo server but uses only one single process.

Motivation for apparent concurrency using a single process Cost of process creation Sharing of information among all connections Apparent concurrency among processes that share memory can be achieved if the total load of requests presented to the server does not exceed its capacity to handle them.

Single-process, Concurrent Server Idea: Arrange for a single process to keep TCP connections open to multiple clients. In this case a server handles a given connection when data arrives. Thus arrival of data is used to trigger processing.

How Concurrent Execution Differs From Single-process Execution In concurrent execution a server creates a separate slave process to handle each new connection. So theoretically it depends on operating systems time slicing mechanism to share the CPU among the processes and thus among the connections. However in reality the arrival of data controls processing.

“Concurrent servers that require little processing time per request often behave in a sequential manner where the arrival of data triggers execution. Timesharing only takes over if the load becomes so high that the CPU canot handle it sequentially.” Process Structure of a connection-oriented server that achieves concurrency using a single process:

How Does Single Process Mechanism Works? In a single process server, a single server process has TCP connections open to many clients. The process blocks waiting for data to arrive. On the arrival of data, on any connection, the process awakens, handles the request and sends the reply.

Advantages of Single-process Server Over Multiple Process Concurrent Server Single- process implementation requires less switching between process contexts. Thus it may be able to handle slightly higher load than implementation that uses multiple processes.

Socket for sockets for connection individual connections requests server Server <--- application process Operating <---system

Details of Single-process Server A single-process server must perform the duties of both master and slave process A set of socket is maintained. One socket is set bound to the well known port at which master can accept connection. The other socket in the set correspond to a connection over which a slave can handle request.

Details of Single-process Server If the descriptor corresponding master socket is ready, it calls accept on the socket to obtain a new connection. If the descriptor corresponding to slave is ready, it calls read to obtain request and answers it. The above step is then repeated.

Algorithm Create a socket and bind to well-known port for the service. Add socket to the list of those on which I/O is possible. Use select to wait for I/O on existing sockets. If original socket is ready, use accept to obtain the next connection, and add the new socket to the list of those on which I/O is possible.

Algorithm (Cont.) If some socket other than the original is ready, use read to obtain the next request, form a response, and use write to send the response back to the client. Continue processing with step 2 above.

The select system call retcode = select (numfds, refds, wrfds, exfds, time) Select provides asynchronous I/O by permitting a single process to wait for the first of any file descriptors in a specified set to become ready. The caller can also specify a maximum timeout for the wait. Arguments –int numfds –&fd_set refds –&fd_set wrfds –&fd_set exfds –&struct timeval returns: number of ready file descriptors

Example - Single Process ECHO Server /* TCPmechod.c - main, TCPechod */ /* include header files here */ #define QLEN 5 /*max. connection queue length */ #define BUFSIZE4096 extern int errno; int echo (int fd) /*echo data until end of file */ int errexit (const char *format, …); int passiveTCP (const char *service, int qlen);

/* main- concurrent TCP server for ECHO service */ int main(int argc, *argv[]) { char *service = “echo”; /*service name or port number */ struct sockaddr_in fsin; /* the from address of a client */ int alen; /* length of a client’s address */ int msock; /* master server socket */ fd_set rfds; /* read file descriptor set */ fd_set afsd; /* active file descriptor set */ int fd; /* check arguments - not detailed here*/

msock = passiveTCP (service, QLEN); FD_ZERO (&afds); FD_SET (msock, &afds); while(1) { memcpy(&rfds, &afds, sizeof(rfds)); if ( select (FD_SETSIZE, &rfds, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0) < 0) errexit (“select: %s\n”, strerror(errno));

if ( FD_ISSET (msock, &rfds)) { int ssock; alen = sizeof (fsin); ssock = accept(msock,(struct sockaddr *)&fsin, &alen); if ( ssock < 0) errexit (“accept: %s\n, strerror (errno)); FD_SET (ssock, &afds); }

for ( fd = 0; fd < FD_SETSIZE; ++fd) if (fd!=msock && FD_ISSET(fd, &rfds)) if (echo(fd) ==0 ) { (void) close (fd); FD_CLR (fd, &afds); }

/* Echo - echo one buffer of data, returning byte count */ int echo (int fd) { char buf[BUFSIZE]; int cc; cc = read (fd, buf, sizeof(buf)); if ( cc < 0 ) errexit(“echo read: %s\n”, strerror(errno)); if (cc && write(fd, buf, cc) < 0 ) errexit (“echo write: %s\n”, strerror(errno)); return cc; }