CPS 472/572 Systems Architecture and Networking
Lecture: 2: The Client-Server Paradigm
Interaction and Implementation of Clients and Servers
Dr. Jennifer Seitzer

Motivation

The client-server paradigm is the most common form of distributed computer application. The two participating hosts assume roles. The client initiates a connection with a server. The server runs constantly, waiting for a client with which to communicate.

We will implement these programs using the socket Application Program Interface. Sockets are available on both UNIX and Windows based platforms. We study the code and view of demonstration of both a client and a server implemented with sockets.

 Introduction to Client-Server

purpose - Application-level protocols provide high-level services such as

Electronic mail
DNS
Remote login
FTP
World Wide Web

architecture of code - All of these applications use client-server architecture

Internet protocols and network applications

Application programs

Client-server paradigm

Server - application is ``listener''

Client - application is proactive

Characteristics of client

·       any application program - becomes client when network service is needed program - Also performs other computations

·       Invoked - directly by user

·       where executes? - Runs locally on user's machine

·       purpose - Initiates contact with server

·       multiple connections - Can access multiple services (one at a time)

·       hardware - does not require special hardware or sophisticated operating system

Characteristics of server

·       definition - Special purpose application dedicated to providing network service

·       invoked - Starts at system initialization time

·       executes - Runs on a remote computer (usually centralized, shared computer)

·       operates - Waits for service requests from clients; loops to wait for next request

·       connections - Will accept requests from arbitrary clients

·       provides one service to each client

·       Requires powerful hardware and sophisticated operating system

·       How many? - usually provides one service - to each client

·       hardware? - Requires powerful hardware and sophisticated operating system

·       ``Server-class'' computers

·       server - Shared, centralized computers that run many server applications are sometimes called ``servers''

·       terminology - More precisely, the applications are the ``servers'' and the computer is a ``server-class computer''

·       hardware necessary - Servers can run on very simple computers...

Message exchanges

·       communication - client and server exchange messages:

·       multiple requests - Client may send multiple requests; server sends multiple responses

·       multiple response - Server may send multiple response - imagine video feed; video servers

Transport protocols and client-server paradigm

o      communication - Clients and servers exchange messages through transport protocols; e.g., TCP or UDP

o      which stack? - Both client and server must have same protocol stack and both interact with transport layer

Multiple services on one computer

o      server - Sufficiently powerful computer - fast enough processor, multi-tasking OS - may run multiple servers

o      concurrent - Servers run as independent processes and can manage clients simultaneously

o      More than one - Can reduce costs by sharing resources among multiple services

o      Reduces management overhead - only one server-class computer to maintain

o      disadvantages - One server can affect others by exhausting server-class computer resources

o      Failure of single server-class computer can bring down multiple servers

 

Identifying a service- a unique port number is assigned each server

What is a socket?

o      Data structure - structure that holds the information needed for communication

o      descriptor table entry - contains a pointer to the the data structure

o      integrated - with all other I/O in UNIX; descriptors exist for files, devices, and network connections.

o      active socket - used by client

o      passive socket - used by server

Application Program Interface

o      purpose - program to interact with protocols

o      program specifies - connection details

o      Passive listen or active open

o      defined by - operating system

o      contains - collection of procedures for application program

o      2 types - group functions into two groups

o      primary functionality needed by clients and servers

o      routines to help programmer

Sockets and UNIX I/O

§       history - Developed as extension to UNIX I/O system

§       descriptor - Uses same file descriptor address space (small integers)

§       sequence of calls - Based on open-read-write-close paradigm

o      how to get the descriptor - open returns a file descriptor, which is used to identify the file to read/write/close

Important socket system calls in Client Server Programming

§       socket - create a new socket

§       close - terminate use of a socket

§       bind - attach a network address and port number to a socket

§       listen - wait for incoming messages

§       accept - begin using incoming connection

§       connect - make connection to remote host

§       send - transmit data through active connection

§       recv - receive data through active connection

Server Architecture

  1. Initialization: getprotobyname - looks up protocol number for TCP
  2. socket - creates socket
  3. bind - creates a port at which to wait
  4. listen - associates socket with incoming requests
  5. Loop: accept - accepts incoming connection
  6. send - send message to client
  7. close - closes connection socket
  8. Sequence of Socket Calls

 Client Architecture

Initialization:

Loop:

 Client calls to recv

§       Loop - The call to recv is in a loop in the client

§       server sends one message - server sends only a single message - why would multiple calls be required?

§       Blocking - Protocol software does not guarantee to deliver data to receiver in the same blocks as generated by the server

§       May travel in different segments

§       recv need not return as much data as was requested

§       Client must make repeated calls to recv until 0 returned

Using client with another server

Other services use similar application protocol:

DAYTIME -- port 13

CHARGEN

MOTD

Specifying port connects to alternate services

Example:

$ client www.netbook.cs.purdue.edu 13

Tue Feb 16 15:55:23 1999

$ client cs.ucla.edu 13

Tue Feb 16 12:56:58 1999

Using another client with your server

Other client that uses same application protocol can test by calling your server

Example: telnet

$ telnet a147.cps.udayton.edu 5193

Trying 131.238.18.47 ...

Connected to a147.cps.udayton.edu.

Escape character is '^]'.

This server has been contacted 1 times.

Connection closed by foreign host.