810 likes | 1.05k Views
ITEC801 Distributed Systems. Client-Server Liu Chapter 5. Important Things. Understanding of basic client server model That client-server can be both connection-oriented and connectionless Have looked at some example code. Client-Server.
E N D
ITEC801Distributed Systems Client-Server Liu Chapter 5
Important Things • Understanding of basic client server model • That client-server can be both connection-oriented and connectionless • Have looked at some example code Client-Server
Client-Server • most prevalent model for distributed computing protocols • it is service-oriented, and employs a request-response protocol Client-Server
Client-Server • an overloaded term • Client-Server system architecture • the terms clients and servers refer to computers • Client hosts make use of services provided on a server host • Client-Server computing paradigm • the terms clients and servers refer to processes • Client processes (objects) make use of a service provided by a server process (object) running on a server host Client-Server
Client-Server Server host Client host … Server request Client process Server process Service Client-Server
Client-Server Client host Server host note server may be contacted by multiple clients … Client-Server
Client-Server Server host Client host and a client may contact multiple servers Client-Server
Example - Napster Client-Server
Applications and Services • On the Internet, many services are client-server applications. • These services are often known by the protocol that the application implements. • For example HTTP, FTP, DNS, finger, gopher, etc. • User applications may also be built using the client-server paradigm. • Most well known Internet protocols are client-server, request-response, and text-based. Client-Server
Session • session refers to the interaction between the server and one client. • The service managed by a server may be accessed by multiple clients, sometimes concurrently. • Each client engages in a separate session with the server Client-Server
Service Session Start Service Accept a client’s request for a session Conduct a session with the client Client-Server
Locating the Service • A mechanism must be available to allow a client process to locate a server • A service can be located by • host name and • Server process protocol port number • This is the scheme for Internet services. Client-Server
Locating Server • Each Internet service is assigned to a specific port number. • In particular, a well-known service such as ftp, HTTP, or telnet is assigned a default port number reserved on each Internet host for that service. Client-Server
Locating Server • At a higher level of abstraction, a service may be identified using a logical name registered with a registry • the logical name will need to be mapped to the physical location of the server process. • If the mapping is performed at runtime then it service’s location may be dynamic Client-Server
Protocol Examples • client and server programs must adhere to protocol specification for the service • Daytime service [RFC867]: • Client: Hello, <client address> here. May I have a timestamp please. • Server: Here it is: (time stamp follows) Client-Server
Protocol Examples • World Wide Web session: • Client: Hello, <client address> here. • Server: Okay. I am a web server and speaks protocol HTTP1.0. • Client: Great, please get me the web page index.html at the root of your document tree. • Server: Okay, here’s what’s in the page: (contents follows). Client-Server
Multiple Servers • Services may be implemented as several server processes • the processes interact as necessary to provide the service • the necessary objects may be partitioned between the servers • the objects may be replicated across the servers Client-Server
Multiple Servers Service Server Client Server Client Server Client-Server
Client-Server • How clear should be the distinction between client and server? • Some systems make it very clear • clients and servers cannot run on the same machine • sometimes the platform for each is different • in others the same machine, even the same process, can be both a client and a server Client-Server
Application Layering • We can distinguish different functionality within a client-server system • Distinction at three levels advocated: • User-Interface level: Interacts with user. • Processing level: Core functionality of application. • Data level: Operated on database/file system Client-Server
User Interface • Directly interfaces with the user • implemented by a client • Interfaces range from the simple to the sophisticated Client-Server
Processing Level • Contains the core functionality of application. • Examples • search engine • Decision support system for stock brokerage Client-Server
Data Level • Contains programs that maintain the actual data on which applications operate • data is persistent • Also responsible for keeping data consistent across different applications. • Can be implemented as a file system or database Client-Server
Layering Example User Interface User-interface level HTML page containing list Keyword Expression HTML Generator Ranked list of page titles Query Generator Processing level Ranking Component Database Queries Web page titles with meta-information Data level Client-Server
Client-Server Architectures User Interface User Interface User Interface User Interface User Interface Application Application Application Database User Interface Application Application Application Database Database Database Database Database Client-Server
Proxy Servers and Caches • A cache is a store of recently used data that is “closer” than the actual objects • when another data object is accessed it is added to the store • proxy servers allow clients to access the proxy’s cache • we will see many other uses of caches Client-Server
Proxy Server Client Server Proxy Server Client Server Client-Server
Callback • client server model • the server is passive: • IPC is initiated by the client • server waits for the arrival of requests and provides responses Client-Server
Callback • Some applications require the server to initiate communication upon certain events. • Examples • monitoring • games • auctioning • voting/polling • chat-room • message/bulletin board • groupware Client-Server
Outline • Clients register with server • Event types they want notification of • Clients provide means for server to call them • Server calls client on event occurence Client-Server
Polling vs. Callback • What if communication does not support callback • Eg., client can’t be called • a client will have to repeatedly poll a passive server if it needs to be notified that an event has occurred at the server end. Client-Server
Polling vs. Callback Polling Callback Server Server … Client Client Client repeatedly issues a request to the server until the desired response is obtained Client registers itself with the server and waits un til the server calls back Client-Server
Two-way communications • Some applications require that both sides may initiate IPC. • Using sockets, duplex communication can be achieved by using two sockets on either side. • With connection-oriented sockets, each side acts as both a client and a server. Client-Server
Callback Process 1 Process 2 request response request response Client-Server
Connections • A client-server application can be either connection-oriented or connectionless. Client-Server
Connectionless Server • No setup • A connectionless server • accepts one request at a time from any client • processes the request • sends the response to the requestor. Client-Server
Connection-Oriented Server • server accepts one connection at a time. • client issues connection request, and waits for its connection to be accepted. • Once a server accepts a connection, it waits for a request from the client. • When a client is connected to the server, it issues a request and waits for the response. Client-Server
Connection-Oriented Server • server receives request, processes it and sends response • then waits for the next request, if any. • The client receives the response and processes it. • If the client issues are further requests, the process repeats itself Client-Server
Basic Connection-Oriented Client-Server Model Server host Client process at head of connection queue server process Server connection queue service Client process connected to server Client-Server
Concurrent, Connection-Oriented Server • A basic connection-oriented server services one client at a time. • duration of client session may be significant, • latency or turnaround time of a client request may be unacceptable due to waiting • To improve the latency can use threads or child processes • a server process spawns a child process or thread to process the protocol for each client. • Such a server is termed a concurrent server, compared to an iterative server. Client-Server
Concurrent, connection-oriented server • A concurrent server uses its main thread to accept connections • spawns a child thread to process the request of each client. • Clients queue for connection, then are served concurrently • concurrency significantly reduces latency Client-Server
Concurrent, connection-oriented server Server host Client process at head of connection queue concurrent server process Main thread accepts connection Server connection queue service child thread processes each client request Client process whose connection has been accepted Client process whose connection has been accepted Client-Server
Connectionless vs. connection-oriented server • A connectionless server • Uses a connectionless IPC API (e.g., connectionless datagram socket) • Sessions with concurrent clients can be interleaved. • A connection-oriented server • Uses a connection-oriented IPC API (e.g. stream-mode socket ) • Sessions with concurrent clients can only be sequential unless the server is threaded Client-Server
Daytime Protocol client server m1 m2 Data representation: text (character strings) m1: null message – any contents will be ignored m2: contains a timestamp, in a format such as Tue Aug 24 18:30:48 2004 Client-Server
Daytime Example 1 • Client – Liu pages 142-144 • Server – Liu pages 146-148 • Connectionless – uses Datagram Socket • Notice client and server classes use other classes • hides the details of the application logic and the underlying service logic. • Programmers of the upper layers need not be aware of which socket types is used for the IPC. Client-Server
UML Diagram - Client presentation logic DaytimeClient1 DatagramPacket DaytimeClientHelper1 MyClientDatagram Socket DatagramSocket sendMessage ( ) receiveMessage ( ) Client-Server application logic
UML Diagram - Server DatagramPacket DatagramMessage presentation + application logic DaytimeServer1 MyServerDatagram Socket DatagramSocket sendMessage ( ) receiveMessage ( ) receiveMessageAnd Sender( ) service logic Client-Server
DaytimeClient1.java import java.io.*; /**contains presentation logic of a DaytimeClient*/ public class DaytimeClient1 { public static void main (String[] args) { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); try { System.out.println(“Welcome to the Daytime Client.\n” + “what is the name of the server host?”); String hostname = br.readline( ); if (hostName.length() == 0) hostName = “localhost” Client-Server
DaytimeClient1.java System.out.println(“What is the port number of the server host?”); String portnum = br.readline(); if (portnum.length == 0) portnum = “13”; System.out.println(“Here is the timestamp received from the server” + DaytimeClientHelper1.getTimeStamp (hostname,portnum); } // end try catch (Exception ex) { ex.printStackTrace(); } //end catch } //end main } //end class Client-Server
DaytimeClientHelper1.java import java.net.*; /**contains application logic of a DaytimeClient*/ public class DaytimeClientHelper1 { public static String getTimeStamp (String hostName, String portNum) { String timestamp = “”; try { InetAddress serverHost = InetAddress.getbyname(hostName); int serverPort = Integer.parseInt(portNum); MyDatagramSocket mySocket = new MyDatagramSocket(); mySocket.sendMessage(serverHost, serverPort, “”); timestamp = mySocket.receiveMessage(); mySocket.close(); } //end try Client-Server