Lecture1 ClientServer
Lecture1 ClientServer
Networking Approach
[email protected]
CLIENT/SERVER COMPUTING
(THE WAVE OF THE FUTURE)
OBJECTIVES
Goal:
How application programs use protocol software to
communicate across networks and internets
A simple definition of CS is
“ server software accepts requests for data from client
software and returns the results to the client”
Elements of C-S Computing
Client
Server
Network
Client machine
Server machine
Network
transfers bits
operates at application’s request
Application determines
what/when/where to send
Meaning of bits
=> Application programs are the entities that communicate
with each other, not the computers or users.
Important point: For 2 application programs to communicate
with each other, one application initiates communication and
the other accepts.
WHERE OPERATIONS ARE DONE
User Interface
Presentation Logic
Application Logic
Server
Client
Presentation Logic
Network
Application Logic
DBMS
CHARACTERISTICS OF A CLIENT
Arbitrary application program
Becomes client temporarily
Can also perform other computations
Invoked directly by user
Runs locally on user’s computer
Actively initiates contact with a server
Contacts one server at a time
True Client-Server Model
Server
Client
Application Logic
Presentation Logic Network
DBMS
Distributed Client-Server Model
Server
Client
Application Logic
Application Logic
Network
DBMS
Presentation Logic
CHARACTERISTICS OF A SERVER
Special-purpose, privileged program
Dedicated to providing one service
Can handle multiple remote clients simultaneously
Invoked automatically when system boots
Executes forever
Needs powerful computer and operating system
Waits passively for client contact
Accepts requests from arbitrary clients
TERMINOLOGY
Server
An executing program that accepts contact over the network
server-class computer
Hardware sufficient to execute a server
Informally
Term “server” often applied to computer
DIRECTION OF DATA FLOW
Facts
Server operates like other applications
uses CPU to execute instructions
Performs I/O operations
Waiting for data to arrive over a network does not require CPU
time
Consequence
Server program uses only CPU when servicing a request
CLIENT-SERVER COMPUTING IS DISTRIBUTED ACCESS,
NOT A DISTRIBUTED COMPUTING.
RPC Look and Feel like Local Calls
results= calling results= called
bar(arguments) procedure bar(arguments) procedure
arguments
arguments
results
results
results=
calling
bar(arguments)
procedure
(client)
client stub server stub
network transport network transport
arguments
results
request message
request message
reply message
reply message
called
procedure
(client)
Network
Client Process
User Mode
Kernel Mode
Message Passing
Facility
CATEGORIES OF SERVERS
File Server
Data Server
Compute Server
Database Server
Communication Server
Video Server
FILE SERVER
File Servers manage a work group’s application and data files, so
that they may be shared by the group.
Very I/O oriented
Pull large amount of data off the storage subsystem and pass the
data over the network
Requires many slots for network connections and a large-capacity,
fast hard disk subsystem.
COMPUTE SERVER
Performs Application logic processing
Compute Servers requires
processors with high performance capabilities
large amounts of memory
relatively low disk subsystems
By separating data from the computation processing,
the compute server’s processing capabilities can be
optimized
CLUSTER AS COMPUTE SERVER
DATA SERVER
Data-oriented; used only for data storage and
management Data
Server
Since a data server can serve more than one
compute server, compute-intensive applications
can be spread among multiple severs
Does not prefer any application logic
processing Compute
Server
Performs processes such as data
validation, required as part of the data
management function.
Requires fast processor, large amount of
memory and substantial Hard disk capacity.
CLUSTER AS HIGH AVAILABLITY DATA SERVER
Data
Server
Compute
Server
DATABASE SERVER
Most typical use of technology in client-server
Accepts requests for data, retrieves the data from its database(or requests
data from another node)and passes the results back.
Compute server with data server provides the same functionality.
The server requirement depends on the size of database, speed with which
the database must be updated, number of users and type of network used.
COMMUNICATION SERVER
Provides gateway to other LANs, networks &
Computers
E-mail Server & internet server
Modest system requirements
multiple slots
fast processor to translate networking protocols
INTERNET SERVER
PC client
Internet Server
Local Area
Network
UNIX workstations
Distributed processing application
connects to remote database
SQ L*
Forms
SQL *Net
TCP/IP UNIX Server
SQL *
Forms
ORACL
E
SQL *Net
TCP/IP
ORACLE
Database Configurations
Ethernet era Intergalactic era
client/server client/server
Database
servers
File Distributed
servers objects
NOS
TP
monitor
Directory Security Distributed file
In Unix, socket procedures (e.g. listen, connect, etc.) are system calls
part of the operating system
implemented in the “top half” of the kernel
when you call the function, control moves to the operating system, and you
are using “system” CPU time
SOCKETS AND SOCKET LIBRARIES
Typically, this DLL makes calls to similar procedures that are part of
the native operating system.
The byte order for the TCP/IP protocol suite is big endian.
BYTE-ORDER TRANSFORMATION
ADDRESS TRANSFORMATION
BYTE-MANIPULATION FUNCTIONS
In network programming, we often need to initialize a field, copy the contents of one field to
another, or compare the contents of two fields.
Cannot use string functions (strcpy, strcmp, …) which assume null character termination.
INFORMATION ABOUT REMOTE HOST
PROCEDURES THAT IMPLEMENT THE SOCKET API
2. Assign transport
endpoint an 3. Determine address
address: bind() of server
CONNECTION-ORIENTED SERVICE
2. Assign transport
2. Assign transport
endpoint an
endpoint an
address (optional):
address: bind( )
bind( )
3. Announce willing
to accept connections: 3. Determine address
listen( ) of server
Connection-oriented service
Server: keeps a count of number of clients that have accessed its
service, then reports the count when a client contacts the server.
Client: displays the data it receives from the server
Example output:
This server has been contacted 10 times
/* To compile me in Solaris, type: gcc -o client client.c -lsocket -lnsl */
/* To compile me in Linux, type: gcc -o client client.c */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
ptrh = gethostbyname(host);
if( ((char *) ptrh) == NULL)
{ fprintf( stderr, "invalid host: %s\n", host);
exit(1);
} Example Client
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);
if ( ((int)(ptrp = getprotobyname("tcp"))) == 0)
{ fprintf( stderr, "cannot map \"tcp\" to protocol number\n");
exit(1);
}
closesocket(sd);
exit(0);
}
Example Client
/* to compile me on Solaris, type: gcc -o server server.c -lsocket -lnsl */
/* to compile me in Linux, type: gcc -o server server.c */
#include <stdio.h>
#include <string.h>
Example Server
/*----------------------------------------------------------------------------
* Program: server
*
* Purpose: allocate a socket and then repeatedly execute the folllowing:
* (1) wait for the next connection from a client
* (2) send a short message to the client
* (3) close the connection
* (4) go back to step (1)
*
* Syntax: server [ port ]
*
* port - protocol port number to use
*
* Note: The port argument is optional. If no port is specified,
* the server uses the default given by PROTOPORT.
*
*----------------------------------------------------------------------------*/
Example Server
main (argc, argv)
int argc;
char *argv[];
{
struct hostent *ptrh; /* pointer to a host table entry */
struct protoent *ptrp; /* pointer to a protocol table entry */
struct sockaddr_in sad; /* structure to hold server's address */
struct sockaddr_in cad; /* structure to hold client's address */
int sd, sd2; /* socket descriptors */
int port; /* protocol port number */
int alen; /* length of address */
char buf[1000]; /* buffer for string the server sends */
Example Server
/* Map TCP transport protocol name to protocol number */
if ( ((int)(ptrp = getprotobyname("tcp"))) == 0) {
fprintf(stderr, "cannot map \"tcp\" to protocol number");
exit (1);
}
/* Create a socket */
sd = socket (PF_INET, SOCK_STREAM, ptrp->p_proto);
if (sd < 0) {
fprintf(stderr, "socket creation failed\n");
exit(1);
}
Example Server
/* Bind a local address to the socket */
if (bind(sd, (struct sockaddr *)&sad, sizeof (sad)) < 0) {
fprintf(stderr,"bind failed\n");
exit(1);
}
/* Specify a size of request queue */
if (listen(sd, QLEN) < 0) {
fprintf(stderr,"listen failed\n");
exit(1);
}
Example Server
/* Main server loop - accept and handle requests */
printf("Server up and running.\n");
while (1) {
alen = sizeof(cad);
fprintf( stderr, "SERVER: Waiting for contact ...\n");