Docsity

Client-Server Paradigm: Concurrent vs. Iterative and Stateful vs. Stateless Servers - Prof, Study notes of Computer Science

Partial preview of the text

Download Client-Server Paradigm: Concurrent vs. Iterative and Stateful vs. Stateless Servers - Prof and more Study notes Computer Science in PDF only on Docsity!

The Client-Server Paradigm (5)

Instructor: Dr. Jeho Park

CECS327 Spring 2009

Iterative servers

Vs.

Concurrent servers

A Concurrent, Connection-oriented Server

Sequence diagram โ€“ EchoServer EchoServer3 EchoClient2 A EchoClient2 B message echo Overlapping may occur at anytime

7 ServerThread.java excerpt class ServerThread implements Runnable { static final String endMessage = "."; MyStreamSocket myDataSocket; EchoServerThread(MyStreamSocket myDataSocket) { this.myDataSocket = myDataSocket; } public void run( ) { boolean done = false; String message; try { // put in here the logic for each client session 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 try catch (Exception ex) { } } //end run } //end class

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

Stateful server

  • A stateful server maintain state information on each active client.
  • State information can reduce the data exchanged, and thereby the response time. Global state information Session state information

Global State Information State information maintained by the server for all the clients throughout the lifetime of a server. E.g., counter protocol

Stateless vs. Stateful server (diagram) Stateless Server Stateful Server

  • Stateless server is straightforward to code -- servers process each request in the same manner.
  • 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. Stateless vs. Stateful server

Session State Information - 2 Another example of a stateful protocol is one for a shopping cart application. Each session must maintain state data that keeps track of the identify of the shopper and the cumulative contents of the shopping cart.

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 should be chosen is a design issue.