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

Slides:



Advertisements
Similar presentations
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
Advertisements

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.
Socket Programming.
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.
An Introduction to Internetworking. Algorithm for client-server communication with UDP (connectionless) A SERVER A CLIENT Create a server-socket (listener)and.
Networking with Java. Basic Concepts A Network exists when two or more computers are connected such that they can communicate data back and forth. There.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Socket Programming -What is it ? -Why bother ?. Basic Interface for programming networks at transport level It is communication end point Used for inter.
CS 352-Socket Programming & Threads Dept. of Computer Science Rutgers University (Thanks,this slides taken from er06/
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Taken from Chapter 3 of Object-Oriented Software Engineering: Practical Software Development using UML and Java by T. Lethbridge and R. Laganiere Basing.
Internet Software Development Lecture 14: Basing Software Development on Reusable Technology From: Object-Oriented Software Engineering, by Lethbridge.
Dynamic Arrays Dynamic arrays are arrays that are re- allocated to a larger size. –See Eck Section 8.3 for details. –For instance, what happens with the.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 21.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology 1.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
Software Engineering, Lecture 4 Mohamed Elshaikh.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Networking Terminology: ISP (Internet service provider) – dialup, dsl, cable LAN (local area network) IP (internet protocol) address, eg
ECEN “Internet Protocols and Modeling”, Spring 2012 Course Materials: Papers, Reference Texts: Bertsekas/Gallager, Stuber, Stallings, etc Class.
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
Client-Server Model of Interaction Chapter 20. We have looked at the details of TCP/IP Protocols Protocols Router architecture Router architecture Now.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
Basing software development on Reusable Technology.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Networking with JavaN-1 Outline Client-Server Example Steps required on the server side Steps required on the client side.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
1 K. Salah Application Layer Module K. Salah Network layer duties.
Network Programming. These days almost all devices.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Sockets and Beginning Network Programming
Networking COMP
Chapter 3 Internet Applications and Network Programming
MCA – 405 Elective –I (A) Java Programming & Technology
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Client-Server Interaction
Client server programming
Presentation transcript:

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