190 likes | 250 Views
CLIENT-SERVER MODEL CONCURRENCY PROCESSES. Chapter 15. Application Layer and Client-Server Model. Comparison between OSI and TCP/IP. 15.1 Client-server model. To make any use of the Internet, application programs should run on the two endpoints of a network connection.
E N D
CLIENT-SERVER MODEL • CONCURRENCY • PROCESSES Chapter 15 Application LayerandClient-Server Model
15.1 Client-server model • To make any use of the Internet, application programs should run on the two endpoints of a network connection. • The applications are the entities that communicate with each other to exchange services • “Client” applications request service • “Server” applications provide service.
Client-Server Relationship: Many-to-One • Servers • Run all the time (i.e. infinite) • Provide service to any client • Typically specialize in providing a certain type of service, e.g. Mail. • Listen to a well-known port and passively open connection. • Clients • Run when needed, then terminate (i.e. finite) • Actively Open TCP or UDP connection with Server’s socket.
15.1 Concurrency • Operation mode could be either iterative or concurrent. • In clients: • Iterative mode: One client at-a-time in serial • Concurrent mode: Several clients run at the same time • In servers: • Iterative mode: serve one client at-a-time (clients wait in a queue) • Concurrent mode: serve multiple clients concurrently and independently. • In addition, servers could chose the Transport layer protocol: • UDP, i.e. connectionless • TCP, i.e. connection-oriented
Connectionless iterative server • Clients’ request arrive inside UDP datagrams and wait in a queue for the server • Server processes one datagram at-a-time, send response back to client inside a UDP datagram • Clients use ephemeral UDP ports • Server uses one well-known UDP port at which all clients’ requests arrive
Connection-Oriented Concurrent Server • Requests and responses are streams of data spanning several segments. • Parent Server passively opens the well-know port to listen for incoming connection requests • Once opened, connections now use ephemeral ports between one client and one Child Server.
15.3 Programs and Processes • Program: code on disk • Process: a running instance of a program. • Process Control Block: • ProcessID, UserID, Program Name. • Where is the data • Which line will execute next • Figure shows two processes of the same program.
Process Creation & fork() • By Replication • One-Parent needed • After the fork(), both parent and child processes execute the same line, the one after the fork()
Return Value of fork() • In the parent process, fork() returns the processID of the just created child • In the child process, fork() simply returns a 0 (which is not a valid processID) • This way, each of the two identical replica can detect whether it is indeed the original parent, or it is the newly created process.
A program that prints the processIDs of the parent and the child
Example of a server program with parent and child processes • Parent Server listens indefinitely (to the well-know port) for connection requests from clients • Once a client requests a connection, a child server process is created to serve this client (on an ephemeral port) • The parent server continues to listen for more clients