CS 580 Client-Server Programming Fall Semester, 2002 Types of Servers |
||
---|---|---|
© 2002, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 01-Oct-02 |
Types of Servers
Iterative verses Concurrent
Iterative
Single process
Handles requests one at a time
Good for low volume & requests that are answered quickly
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()); } } }
Concurrent
Handle multiple requests concurrently
Normally uses thread/processes
Needed for high volume & complex requests
Harder to implement than iterative
Must deal with currency
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.
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 }
Stateless verses Stateful Servers
State information
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