the client server model part ii l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
The Client-Server Model – part II PowerPoint Presentation
Download Presentation
The Client-Server Model – part II

Loading in 2 Seconds...

play fullscreen
1 / 25

The Client-Server Model – part II - PowerPoint PPT Presentation


  • 154 Views
  • Uploaded on

The Client-Server Model – part II. Connectionless server vs. connection-oriented 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 .

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'The Client-Server Model – part II' - parker


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
connectionless vs connection oriented server
Connectionless vs. Connection-Oriented Server
  • A connectionless server
    • Uses a connectionless IPC API (e.g., connectionlessdatagramsocket)
    • Sessions with concurrent clients can beinterleaved.
  • A connection-oriented server
    • Uses a connection-oriented IPC API (e.g. stream-modesocket )
    • Sessions with concurrent clients can only besequentialunless the server isthreaded.
echoserver1 connection less udp
EchoServer1 (Connectionless--UDP)

public class EchoServer1 {

public static void main(String[] args) {

// instantiates a datagram socket for both sending

// and receiving data

MyServerDatagramSocket mySocket = new MyServerDatagramSocket(serverPort);

while (true) { // forever loop

DatagramMessagerequest =

mySocket.receiveMessageAndSender();

String message = request.getMessage( );

mySocket.sendMessage(request.getAddress( ),

request.getPort( ), message);

} //end while

http://ise.gmu.edu/~yhwang1/SWE622/Sample_Codes/chapter5

concurrent client sessions with echoserver1
Concurrent client sessions with EchoServer1

Messages from clients will be lost if the server is not ready yet.

echoserver2 connection oriented tcp
EchoServer2 (Connection-oriented--TCP)

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

http://ise.gmu.edu/~yhwang1/SWE622/Sample_Codes/chapter5

slide8
Iterative servers

Vs.

Concurrent servers

concurrent server
Concurrent Server
  • A connection-oriented server can be threaded so that it can serve multiple clients concurrently/simultaneously. Such a server is said to be a concurrent server.
  • An unthreadedconnection-oriented server is said to be an iterative server (e.g., EchoServer2).
echoserver3 concurrent server
EchoServer3 (concurrent server)

ServerSocket myConnectionSocket

= new ServerSocket(serverPort);

while (true) { // forever loop

MyStreamSocket myDataSocket = new

MyStreamSocket myConnectionSocket.accept( ));

Thread aThread =

new Thread(new ServerThread(myDataSocket));

aThread.start();

} //end while forever

http://ise.gmu.edu/~yhwang1/SWE622/Sample_Codes/chapter5

serverthread class
ServerThread Class

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
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

session state information
Session State Information

For some protocols or applications, a server must maintain informationspecific to a client during itsservicesession.

Consider a network service such as file transfer. Afile is typically transferred in blocks, requiring several rounds of data exchanges to complete the file transfer. The dialog during a session proceeds roughly as follows:

Client: Please send me the file foo in directory someDir.

Server: Okay. Here is block1 of the file

Client: Got it.

Server. Okay. Here is block2 of the file

Client: Got it.

Server. Okay. Here is block3 of the file

Client: Got it.

stateful server
Stateful Server
  • A stateful server maintains statefulinformationon each active client.
  • Stateful information can reduce the data exchanged, and thereby the response time.
stateful vs stateless server
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.
session state information 2
Session State Information - 2

With a protocol such as ftp, there is a need for the server to keep track of the progress of the session, such as which block of the file needs to be fetched next. A server does so by maintaining a set of state for each session, known as thesession state data. For the file transfer protocol, the session state data may include thename of the file being transferred, and the current block count.

Another example of a stateful protocol is one for a shopping cart application. Each session must maintain state data that keeps track of theidentifierof the shopper and the cumulative contents of the shopping cart.

state data storage
State Data Storage

In our example, the state data – the sleep time interval - is stored in a local variable in the run method of each thread. Since each client is serviced by a separate thread, the local variablesuffices 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.

http session
HTTP Session

public class SWE622 extends HttpServlet {

public void init(ServletConfig config) throws ServletException { super.init(config); }

public void service( HttpServletRequestreq, HttpServletResponse resp)

throws ServletException, IOException

{ …

HttpSessionsession = req.getSession(true);

session.putValue (“Department", “ISE”);

session.putValue (“University", “GMU”);

… }

stateful vs stateless server23
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.
a client can contact multiple servers
A client can contact multiple servers

A client process may require the services from different 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.

summary
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.