160 likes | 239 Views
Introduction. Chapter 1. Part III Client/Server Organization. Process Organization. How are processes organized in a DS? Client/Server: very famous model Server : A process implementing a specific service (Web site, file system) Client : a process that requests a service from the server.
E N D
Introduction Chapter 1 Part III Client/Server Organization
Process Organization • How are processes organized in a DS? • Client/Server: very famous model • Server: A process implementing a specific service (Web site, file system) • Client: a process that requests a service from the server
Clients and Servers 1.25 • General interaction between a client and a server.
An Example Client/Server (1) • import java.io.*; • import java.net.*; • class Server { • public static void main(String a[]) throws IOException { • int port = 1969; //some port! • Socket s; • // Create a server socket • ServerSocket ss = new ServerSocket(port); • // daemon like thing • while (true) { • s = ss.accept(); // accept a new client connection • /* CODE TO PROCESS REQUEST HERE */}}} Simple Server
An Example Client/Server (2) • // I/O streams for the socket • BufferedReader is = null; • PrintStream os = null; • // Get these I/O streams • try { • is = new BufferedReader(new • InputStreamReader(s.getInputStream())); • os = new PrintStream(s.getOutputStream()); • // send your greating to the client • os.println("Waiting for your request."); • os.flush(); Simple Server
An Example Client and Server (3) • /* receive the client's request. Example request: 1:source.txt */ • String request = is.readLine(); • /* PROCESS COMMAND */ • // close "this" connection with the client • s.close(); • } • catch (IOException e) { • System.out.println("IO Exception: " + e); • } • } Simple Server
An Example Client and Server (4) • import java.io.*; • import java.net.*; • class Client { • public static void main(String a[]) throws IOException { • int port = 1969; //some port! • // open the connection to the server • Socket s = new Socket("jalal", port); //my machine • // get I/O streams • PrintStream os = new PrintStream(s.getOutputStream()); • BufferedReader is = new BufferedReader(new • InputStreamReader(s.getInputStream())); Simple Client
An Example Client and Server (5) • // get the server welcome message • System.out.println("Server says: " + is.readLine()); • // send a request to the server • os.println(<some request>); • os.flush(); • // receive the servers response • System.out.println("Server Says: " + is.readLine()); • s.close(); • } • } Simple Client
An Example Client and Server (6) • DataInputStream is = new DataInputStream(s.getInputStream()); • readLine is depricated in DataInputStream • System.out.println("Server says: " + is.readLine()); • BufferedReader is = new BufferedReader(new InputStreamReader(s.getInputStream())); Simple Client
3-Level Processing Vertical Distribution User Interface Application Server Data Server
3-Level Processing 1-28 • The general organization of an Internet search engine into three different layers
Multitiered Architectures (1) 1-29 • Alternative client-server organizations (a) – (e).
Multitiered Architectures (2) 1-30 • An example of a server acting as a client.
Modern Architectures Horizontal Distribution 1-31 • An example of horizontal distribution of a Web service.
Modern Architectures Web Server Presentation Server Application Server Data Server
Modern Architectures XML Output Queries/ Responses Client Server Client Request Client Request App Server Web Server HTML WML Data Server Presentation Server Server Response