SDSU CS 580 Client-Server Programming
Fall Semester, 2002
Types of Servers
Previous    Lecture Notes Index    Next    
© 2002, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 01-Oct-02

Contents of Doc 12, Types of Servers


References

Internetworking with TCP/IP, BSD Socket Version Vol. 3, Comer, Stevens, Prentice-Hall, 1993


Doc 12, Types of Servers Slide # 2

Types of Servers






Doc 12, Types of Servers Slide # 3

Iterative verses Concurrent


Iterative

Single process

Handles requests one at a time

Good for low volume & requests that are answered quickly



Doc 12, Types of Servers Slide # 4
Iterative Example

import java.net.Socket;
import java.net.ServerSocket;
import java.io.*;
import java.util.Date;
class SimpleDateServer {
   public static void main(String[] args) throws IOException {
      ServerSocket acceptor = new ServerSocket(4567);
      while (true) {
         Socket client = acceptor.accept();
         processRequest( 
            client.getInputStream(),
            client.getOutputStream());
         client.close();
      }
   }

   static void processRequest(InputStream in,OutputStream out)
      throws IOException {
      
      BufferedReader parsedInput = 
            new BufferedReader(new InputStreamReader(in));
      PrintWriter parsedOutput = new PrintWriter(out,true);
      parsedOutput.println(now.toString());
      }
   }
}


Doc 12, Types of Servers Slide # 5
Concurrent

Handle multiple requests concurrently

Normally uses thread/processes

Needed for high volume & complex requests

Harder to implement than iterative

Must deal with currency


Doc 12, Types of Servers Slide # 6
Concurrent Server Example

| server |
server := SocketAccessor newTCPserverAtPort: 9009.
server listenFor: 5.
   
 [ | acceptedSocket |
   "wait for a new connection"
   acceptedSocket := server accept.
   "fork off processing of the new stream socket"
   [ | stream char |
      stream := acceptedSocket readAppendStream.
      stream lineEndTransparent.
      [ (char := stream next) isNil ] whileFalse: [
         stream nextPut: char; commit ].
      stream close. 
   ] forkAt: Processor userSchedulingPriority -1.
] repeat. 


Doc 12, Types of Servers Slide # 7
Single Process/Thread Concurrent Server

One can implement a concurrent server using one thread/process

while (true) {
   check if any new connects (non-block accept)
   if new connection accept
   process a little on each current request
}

Doc 12, Types of Servers Slide # 8

Stateless verses Stateful Servers


State information


Stateless server


Stateful server


State information cause problems




Doc 12, Types of Servers Slide # 9

Modes of Operation


Stateful servers sometimes have different modes of operation

Each mode has a set of legal commands


In Login mode only the commands password & username are accepable

After successful login client-server connection in transaction mode

In transaction mode command X, Y Z are legal


These modes are also called server states or just states



Copyright ©, All rights reserved.
2002 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 01-Oct-02    Next