










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











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