We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Modified over 3 years ago
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among many… We will use a client server architecture Select client-server architecture because we are going to build a client-server framework upon which we can later build applications. Once we build a client-server framework, we can then SEE how the framework works. Once we see how the framework workds, we can then REUSE this framework to build applications.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 2 3.4 The Client-Server Architecture A distributed system is a system in which: computations are performed by separate programs … normally running on separate pieces of hardware … that co-operate to perform the task of the system. Server: A program that provides a service for other programs that connect to it using a communication channel Client A program that accesses a server (or several servers) to obtain services A server may be accessed by many clients simultaneously
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 3 Sequence of activities in a client-server system 1.The server starts running 2.The server waits for clients to connect. (listening) 3.Clients start running and perform operations —Some operations involve requests to the server 4.When a client attempts to connect, the server accepts the connection (if it is willing) 5.The server waits for messages to arrive from connected clients 6.When a message from a client arrives, the server takes some action in response, then resumes waiting 7.Clients and servers continue functioning in this manner until they decide to shut down or disconnect
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 4 A server program communicating with two client programs
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 5 Note: Certainly possible for the same program to be both a client as well as a server at the same time. A database server might need to be connected to another server in order to get more data. Here it is both server and a client of other server. Also possible for clients and servers to share the same box. More likely, separate computers and generally in different locations.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 6 Alternatives to the client server architecture Have a single program on one computer that does everything Have no communication — Each computer performs the work separately -Could have common communications areas. Have some mechanism other than client-server communication for exchanging information —E.g. one program writes to a database; the other reads from the database
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 7 Advantages of client-server systems The work can be distributed among different machines The clients can access the server’s functionality from a distance The client and server can be designed separately They can both be simpler All the data can be kept centrally at the server Conversely, data can be distributed among many different geographically-distributed clients or servers The server can be accessed simultaneously by many clients Competing clients can be written to communicate with the same server, and vice-versa
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 8 Example of client-server systems The World Wide Web Email Network File System Transaction Processing System Remote Display System Communication System Database System In order to understand the framework we are about to build, let’s examine the required functionality.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 9 Activities of a server 1.Initializes itself 2.Starts listening for clients 3.Handles the following types of events originating from clients 1.accepts connections 2.responds to messages 3.handles client disconnection 4.May stop listening too many clients; periodic maintenance… 5.Must cleanly terminate
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 10 Activities of a client 1.Initializes itself 2.Initiates a connection 3.Sends messages 4.Handles the following types of events originating from the server 1.responds to messages 2.handles server disconnection 5.Must cleanly terminate initiate a connection to a server respond to events triggered by the server do:respond to messages and handle server disconnection interact with the user, sending messages to the server as necessary terminate initialize
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 11 Threads in a client-server system – really, both must have concurrent threads of control.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 12 Thin- versus fat-client systems Thin-client system (a) Client is made as small as possible Most of the work is done in the server. Client easy to download over the network Client machines are usually inexpensive But there are downsides: —Bandwidth required may be prohibitive for large n.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 13 Thin- versus fat-client systems Fat-client system (b) As much work as possible is delegated to the clients. Server can handle more clients Bandwidth reduced Downsides: 1. more expensive client machines; 2. all copies of software need to be upgraded on all clients when changes made 3. Maintenance made more difficult.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 14 Communications protocols The messages the client sends to the server form a language. — The server has to be programmed to understand that language. The messages the server sends to the client also form a language. — The client has to be programmed to understand that language. When a client and server are communicating, they are in effect having a conversation using these two languages The two languages and the rules of the conversation, taken together, are called the protocol
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 15 Tasks to perform to develop client-server applications 1.Design the primary work to be performed by both client and server 2.Design how the work will be distributed 3.Design the details of the set of messages that will be set 1.These can be nicely modeled with current tools. 4.Design the mechanism for 1.Initializing 2.Handling connections 3.Sending and receiving messages 4.Terminating
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 16 3.5 Technology Needed to Build Client- Server Systems (TCP/IP) Internet Protocol (IP) Route messages from one computer to another Long messages are normally split up into small pieces (SDLC, packets, etc.) Transmission Control Protocol (TCP) Handles connections between two computers Computers can then exchange many IP messages over a connection Assures that the messages have been satisfactorily received A host has an IP address and a host name Several servers can run on the same host. Each server is identified by a port number (0 to 65535). To initiate communication with a server, a client must know both the host name and the port number
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 17 How do we do all this in Java?
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 18 Establishing a connection in Java The java.net package Permits the creation of a TCP/IP connection between two applications Before a connection can be established, the server must start listening to one of the ports for a client hook up: It creates an instance of ServerSocket and listens! ServerSocket serverSocket = newServerSocket(port); For a client to connect to a server: the client executes: Socket clientSocket= new Socket(host, port); Identifies hostname or IP address and the port number of the server (who is hopefully listening).
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 19 Server must have following code embedded in a loop: Server will wait – awaiting a connect request from a client. Socket clientSocket = serverSocket.accept(); Once it gets a connect request from a client, the server will establish a socket to handle the new connections. Once both client and server have instances of Socket, we can now communicate in both directions.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 20 Exchanging information in Java Each program uses an instance of — InputStream to receive messages from the other program — OutputStream to send messages to the other program —These are found in package java.io output = clientSocket.getOutputStream(); input = clientSocket.getInputStream(); One’s output stream is the other’s input stream. But the transmission is in bytes! Java provides us facilities to convert raw bytes into other forms.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 21 Sending and receiving messages without any filters (raw bytes) output.write(msg); msg = input.read(); or using DataInputStream / DataOutputStream filters output.writeDouble(msg); msg = input.readDouble(); These filters allow transmission of Java’s primitive types, such as float, int, char, etc. or using ObjectInputStream / ObjectOutputStream filters output.writeObject(msg); msg = input.readObject(); Java allows the transmission of objects with these filters.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 22 Sending Objects Objects must implement the interface java.io.Serializable Data in the instance variables must also be serializable. If so, Java uses a process called serialization to convert objects in the ObjectOutputStream into binary streams for transmission and will convert binary streams back into objects on the other end via ObjectInputStream. We also use serialization to save objects to binary files.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 23 Wrappers In order to use the object input and object output streams, one must ‘wrap’ the binary input/output streams, as in: (Recall: output = clientSocket.getOutputStream();) (byte data) output = new ObjectOutputStream (clientSocket.getOutputStream()); Now, can send object via: output.writeObject(msg); and in order to receive objects, you create an object input stream: input = new ObjectInputStream(clientSocket.getInputStream()); Then, the following statement must be executed in a loop: msg = input.readObject(); The readObject method will wait until an object is received over the socket, or until an I/O error occurs. An I/O error would occur if the program at the other end of the connection is terminated.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 24 Now, we are ready to implement a client-server framework for the exchange of objects.
Socket Programming ENTERPRISE JAVA. 2 Content Sockets Streams Threads Readings.
Network Programming Chapter 11 Lecture 6. Networks.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
CSE 240 Lecture 8. © Lethbridge/Laganière 2001 Chapter 5: Modelling with classes2 Overview Begin discussing Chapter 3 - Reuse.
Basic Socket Programming with Java. What is a socket? Generally refers to a stream connecting processes running in different address spaces (across.
1 Creating a network app Write programs that run on different end systems and communicate over a network. e.g., Web: Web server software communicates.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
1 Java Networking – Part I CS , Spring 2008/9.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn: To understand Java networking with URLs, sockets and datagrams. To implement Java.
1 Programming Section 9 James King 12 August 2003.
System Programming Practical session 10 Java sockets.
Network Programming. The biggest difficult part in networking programming lies in understanding networking not in using java networking package. Since.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
CS-3013 & CS-502, Summer 2006 Network Input & Output1 CS-3013 & CS-502, Summer 2006.
Systems Architecture, Fourth Edition1 Internet and Distributed Application Services Chapter 13.
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
© 2019 SlidePlayer.com Inc. All rights reserved.