920 likes | 1.2k Views
Client-Server and Multicast Communication. René de Vries Based on slides by M.L. Liu and M. van Eekelen. Overview Client Server Communication. Chapter 5: Liu Introduction Reviewing, usage and definitions Connectionless client-server topology Connection oriënted client-server topology
E N D
Client-Server and Multicast Communication René de Vries Based on slides by M.L. Liu and M. van Eekelen Client-Server and Multicast Communication
Overview Client Server Communication Chapter 5: Liu • Introduction • Reviewing, usage and definitions • Connectionless client-server topology • Connection oriënted client-server topology • Concurrent servers • Stateful and Stateless servers • Notes and Summary • References Client-Server and Multicast Communication
Introduction • The Client-Server paradigm is the most prevalent model for distributed computing protocols. • It is the basis of all distributed computing paradigms at a higher level of abstraction. • It is service-oriented, and employs a request-response protocol. Client-Server and Multicast Communication
The Client-Server Paradigm • A server process, running on a server host, provides access to a service. • A client process, running on a client host, accesses the service via the server process. • The interaction of the process proceeds according to a protocol. Client-Server and Multicast Communication
Client-server, an overloaded term Client-Server and Multicast Communication
Client-server applications and services • An application based on the client-server paradigm is a client-server application. • On the Internet, many services are Client-server applications. These services are often known by the protocol that the application implements. • Well known client-server Internet services include HTTP, FTP, DNS, finger, etc. • User applications may also be built using the client-server paradigm. Client-Server and Multicast Communication
Place in the Internet Protocol Stack Client-Server and Multicast Communication
A service session A Session is an interaction between the server and one client. Client-Server and Multicast Communication
The interprocess communications and event synchronization • Typically, the interaction of the client and server processes follows a request-response pattern. Client-Server and Multicast Communication
Session IPC examples The dialog in each session follows a pattern prescribed in the protocol specified for the service. Daytime service [RFC867]: Client: Hello, <client address> here. May I have a timestamp please. Server: Here it is: (time stamp follows) World Wide Web session: Client: Hello, <client address> here. Server: Okay. I am a web server and I speak 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 and Multicast Communication
The Protocol for a Network Service • A protocol is needed to specify the rules that must be observed by the client and the server during the conducting of a service. • how the service is to be located • the sequence of interprocess communication (dynamics) • the representation and interpretation of data exchanged with each IPC (signature) • On the Internet, such protocols are specified in the RFC-series. The Request For Comments (RFC) document series is a set of technical and organizational notes about the Internet (originally the ARPANET), beginning in 1969. Memos in the RFC series discuss many aspects of computer networking, including protocols, procedures, programs, and concepts, as well as meeting notes and opinions. Client-Server and Multicast Communication
Locating the service • A mechanism must be available to allow a client process to locate a server for a given service. • A service can be located through the address of the server process, in terms of the host name and protocol port number assigned to the server process. This is the scheme for Internet services. 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. • 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 (that is, when a client process is run), then it is possible for the service’s location to be dynamic, or moveable. Client-Server and Multicast Communication
Overview Client Server Communication • Introduction • Connectionless client-server topology • Connection oriënted client-server topology • Iterative and concurrent servers • Stateful and Stateless servers • Notes and Summery • References Client-Server and Multicast Communication
Connectionless Server A connectionless server accepts one request at a time from any client, processes the request, and sends the response to the requestor. Client-Server and Multicast Communication
Software Engineering for a Network Service Client-Server and Multicast Communication
Example protocol: daytime Defined in RFC867 Client-Server and Multicast Communication
Daytime Protocol Client-Server and Multicast Communication
Daytime Protocol Implementation Sample 1 – using connectionless sockets: DaytimeServer1.java DaytimeClient1.java Client-Server and Multicast Communication
The getAddress and getPort Methods Client-Server and Multicast Communication
Connectionless Echo Server (advanced) DatagramSocket ds = new DatagramSocket(port); while (true) { try { // create a new datagram packet byte[] buffer = new byte[MAXLEN]; DatagramPacket dp = new DatagramPacket(buffer, MAXLEN); ds.receive(dp); len = dp.getLength(); cAddr = dp.getAddress(); cPort = dp.getPort(); String s = new String(dp.getData(), 0, len); System.out.println(dp.getAddress() + " at port " + dp.getPort() + " says " + s); // create a datagram packet to send to client DatagramPacket theEcho = new DatagramPacket(buffer,len, cAddr, cPort); ds.send(theEcho); } // end try … } // end while Client-Server and Multicast Communication
Concurrent client sessions with EchoServer1 Client-Server and Multicast Communication
Overview Client Server Communication • Introduction • Connectionless client-server topology • Connection oriënted client-server topology • Iterative and concurrent servers • Stateful and Stateless servers • Notes and Summary • References Client-Server and Multicast Communication
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 and Multicast Communication
Connection-Oriented Client-Server applications In a connection-oriented client-server application: • The server is passive: it listens and waits for connection requests from clients, and accepts one connection at a time. • A client issues a 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. • When a server receives a request, it processes the request and sends a response, then wait for the next request, if any. • The client receives the response and processes it. If there are further requests, the process repeats itself. Client-Server and Multicast Communication
The Basic Connection-Oriented Client-Server Model Client-Server and Multicast Communication
EchoServer2 (Connection-oriented) excerpt ServerSocket myConnectionSocket = new ServerSocket(serverPort); while (true) { // forever loop MyStreamSocket myDataSocket = new MyStreamSocket (myConnectionSocket.accept( )); boolean done = false; while (!done) { message = myDataSocket.receiveMessage( ); if ((message.trim()).equals (endMessage)){ myDataSocket.close( ); done = true; } //end if else { myDataSocket.sendMessage(message); } //end else } //end while !done } //end while forever Client-Server and Multicast Communication
Two consecutive client sessions with echo server2 Client-Server and Multicast Communication
Overview Client Server Communication • Introduction • Connectionless client-server topology • Connection oriënted client-server topology • Concurrent servers • Stateful and Stateless servers • Notes and Summary • References Client-Server and Multicast Communication
Concurrent, Connection-Oriented Server • A connection-oriented server services one client at a time. • If the duration of each client session is significant, then the latency or turnaround time of a client request becomes unacceptable if the number of concurrent client processes is large. • To improve the latency, a server process spawns a child process or child thread to process the protocol for each client. Such a server is termed a concurrent server, compared to an iterative server. Client-Server and Multicast Communication
Concurrent, connection-oriented server - 2 • A concurrent server uses its main thread to accept connections, and spawns a child thread to process the protocol for each client. • Clients queue for connection, then are served concurrently. The concurrency reduces latency significantly. Client-Server and Multicast Communication
Connection-oriented server: latency analysis For a given server S, let • Tc be the expected time that S takes to accept a connection, • Tp be the expected time S takes to process the protocol for a client, • N be the expected number of concurrent clients requiring the service of S. Client-Server and Multicast Communication
Connection-oriented Daytime Server …theServer = new ServerSocket(thePort); p = new PrintWriter(System.out); try { p.println("Echo Server now in business on port " + thePort ); p.flush(); theConnection = theServer.accept(); // read a line from the client theInputStream = new BufferedReader (new InputStreamReader (theConnection.getInputStream())); p = new PrintWriter(theConnection.getOutputStream()); while (!done){ theLine = theInputStream.readLine(); if (theLine == null) done = true; else{ p.println(theLine); p.flush(); } } theConnection.close(); Connection acceptance Protocol processing Client-Server and Multicast Communication
theServer = new ServerSocket(thePort); p = new PrintWriter(System.out); try { p.println("dayTime Server now in business on port " + thePort ); p.flush(); while (true) { theConnection = theServer.accept(); daytimeServerThread theThread = new daytimeServerThread(theConnection); theThread.start(); } } public class daytimeServerThread extends Thread { Socket theConnection; public daytimeServerThread(Socket s) { theConnection = s; } public void run() { try { PrintWriter p; p = new PrintWriter(theConnection.getOutputStream()); p.println(new Date()); p.flush(); theConnection.close(); } catch (IOException e) { System.err.println(e); } } // end try } // end thread class Connection-oriented Concurrent DayTime Server ConcurrentDaytimeServer.javaDaytimeServerThread.java Client-Server and Multicast Communication
public class echoServer { public static void main(String[] args) { ServerSocket theServer; int thePort; Socket theConnection; PrintWriter p; BufferedReader theInputStream; String theLine; boolean done = false; … theServer = new ServerSocket(thePort); p = new PrintWriter(System.out); try { theConnection = theServer.accept(); // read a line from the client theInputStream = new BufferedReader (new InputStreamReader (theConnection.getInputStream())); p = new PrintWriter(theConnection.getOutputStream()); while (!done){ theLine = theInputStream.readLine(); if (theLine == null) done = true; else { p.println(theLine); p.flush(); } // end if } //end while theConnection.close(); } // end try … Connection-oriented Echo Server Client-Server and Multicast Communication
Sequence diagram – EchoServer3 Client-Server and Multicast Communication
Server Thread class template class ServerThread implements Runnable { static final String endMessage = "."; MyStreamSocket myDataSocket; ServerThread(MyStreamSocket myDataSocket) { this.myDataSocket = myDataSocket; } public void run( ) { boolean done = false; String message; try { //add code here }// end try catch (Exception ex) { System.out.println("Exception caught in thread: " + ex); } } //end run } //end class Client-Server and Multicast Communication
Concurrent Echo Server See ConcurrentEchoServer.java See EchoServerThread.java Client-Server and Multicast Communication
Overview Client Server Communication • Introduction • Connectionless client-server topology • Connection oriënted client-server topology • Iterative and concurrent servers • Stateful and Stateless servers • Notes and Summary • References Client-Server and Multicast Communication
Stateful vs. stateless server In actual implementation, a server may be • Stateless • Stateful • A hybrid, wherein the state data is distributed on both the server-side and the client-side. Which type of server is chosen is a design issue. Client-Server and Multicast Communication
Stateful server • A stateful server maintains stateful information on each active client. • Stateful information can reduce the data exchanged, and thereby the response time. Client-Server and Multicast Communication
Stateful vs. Stateless server • Stateless server is straightforward to code. • Stateful server is harder to code, but the state information maintained by the server can reduce the data exchanged, and allows enhancements to a basic service. • Maintaining stateful information is difficult in the presence of failures. Client-Server and Multicast Communication
State Data Storage State data can be stored in a local variable in the run method of each thread. When each client is serviced by a separate thread, a local variable suffices as a storage for the state data. Using local variables in a thread to store session state data is adequate for a network service server. In complex network applications such as shopping carts, more complex mechanisms are needed for state data storage. Client-Server and Multicast Communication
Overview Client Server Communication • Introduction • Connectionless client-server topology • Connection oriënted client-server topology • Concurrent servers • Stateful and Stateless servers • Notes and Summary • References Client-Server and Multicast Communication
A client can contact multiple servers A process may require the service of multiple servers. For example, it may obtain a timestamp from a daytime server, data from a database server, and a file from a file server. Client-Server and Multicast Communication
Middleware A process can serve as a intermediary, or middleware, between a client and a server. Client-Server and Multicast Communication
Designing a Network Service • Because of its inherent complexity, network software is notoriously difficult to test. • Use the three-layered software architecture and modularize each layer on both the client and the server sides. • Use an incremental or stepwise approach in developing each module. Starting with stubs for each method, compile and test a module each time after you put in additional details. • Develop the client first. It is sometimes useful to employ an Echo server (to be introduced in the next section) which is known to be correct and which uses a compatible IPC mechanism to test the client independent of the server; doing so allows you to develop the client independent of the server. • Use diagnostic messages throughout each program to report the progress of the program during runtime. • Test the client-server suite on one machine before running the programs on separate machine. Client-Server and Multicast Communication
Summary You have been introduced to the client-server paradigm in distributed computing. Topics covered include: • The difference between the client-server system architecture and the client-server distributed computing paradigm. • Definition of the paradigm and why it is widely adopted in network services and network applications. • The issues of service sessions, protocols, service location, interprocess communications, data representation, and event synchronization in the context of the client-server paradigm. • The three-tier software architecture of network applications: Presentation logic, application logic, and service logic. • Connectionless server versus connection-oriented server. • Iterative server versus concurrent server and the effect on a client session. • Stateful server versus stateless server. • In the case of a stateful server: global state information versus session state information. Client-Server and Multicast Communication
References & Exercises • Deitel & Deitel“Java How to Program” • SUN Java reference pages java.sun.com • Liu“Distributed Computing - principles and applications” • Fred Halsall“Data communications, computer networks and open systems” Selfstudy Exercises Chapter 5: Exercises 1, 2, 9, 12.a Client-Server and Multicast Communication
Multicast Communication Client-Server and Multicast Communication