1 Chapter 9 Network Programming. 2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

Building Distributed Applications using JAVA - RMI
What is RMI? Remote Method Invocation –A true distributed computing application interface for Java, written to provide easy access to objects existing.
Java Network Programming Vishnuvardhan.M. Dept. of Computer Science - SSBN Java Overview Object-oriented Developed with the network in mind Built-in exception.
RMI Varun SainiYing Chen. What is RMI? RMI is the action of invoking a method of a remote interface on a remote object. It is used to develop applications.
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
Remote Method Invocation in Java Bennie Lewis EEL 6897.
Advanced Programming Rabie A. Ramadan Lecture 4. A Simple Use of Java Remote Method Invocation (RMI) 2.
Java Remote Method Invocation (RMI) In Java we implement object systems: O1O2 O3 thread 1thread 2 execution scheme JVM 1JVM 2 distribution scheme.
Remote Method Invocation
Company LOGO Remote Method Invocation Georgi Cholakov, Emil Doychev, University of Plovdiv “Paisii.
FONG CHAN SING (143334) WONG YEW JOON (143388). JAVA RMI is a distributive system programming interface introduced in JDK 1.1. A library that allows an.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
DISTRIBUTED FILE SYSTEM USING RMI
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
6/13/2015B.Ramamurthy1 System Models Bina Ramamurthy (Based on Slides from CDK text)
1 HANDOUT 14 Remote Method Invocation (RMI) BY GEORGE KOUTSOGIANNAKIS THIS DOCUMENT CAN NOT BE REPRODUCED OR DISTRIBUTED WITHOUT TH E WRITTEN PERMISSION.
Sockets  Defined as an “endpoint for communication.”  Concatenation of IP address + port.  Used for server-client communication.  Server waits for.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Introduction to Remote Method Invocation (RMI)
Java Remote Object Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Systems Architecture, Fourth Edition1 Internet and Distributed Application Services Chapter 13.
Lesson 3 Remote Method Invocation (RMI) Mixing RMI and sockets Rethinking out tic-tac-toe game.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Java RMI Essentials Based on Mastering RMI Rickard Oberg.
1 Java Programming II Java Network II (Distributed Objects in Java)
+ A Short Java RMI Tutorial Usman Saleem
Cli/Serv.: rmiCORBA/131 Client/Server Distributed Systems v Objectives –introduce rmi and CORBA , Semester 1, RMI and CORBA.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
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.
Silberschatz, Galvin, and Gagne  1999 Applied Operating System Concepts Chapter 15: Distributed Communication Sockets Remote Procedure Calls (RPCs) Remote.
Java Remote Method Invocation RMI. Idea If objects communicate with each other on one JVM why not do the same on several JVM’s? If objects communicate.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 43 Remote Method Invocation.
Java Programming: Advanced Topics 1 Networking Programming Chapter 11.
Fall 2007cs4251 Distributed Computing Umar Kalim Dept. of Communication Systems Engineering 17/10/2007.
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
 Java RMI Distributed Systems IT332. Outline  Introduction to RMI  RMI Architecture  RMI Programming and a Sample Example:  Server-Side RMI programming.
Remote Method Invocation A Client Server Approach.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
Java Distributed Object Model A remote object is one whose methods can be invoked from another JVM on a different host. It implements one or more remote.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
CSC 480 Software Engineering Lab 6 – RMI Nov 8, 2002.
Netprog Java RMI1 Remote Method Invocation.
RMI1 Remote Method Invocation Adapted from “Core Java 2” by Cay Horstmann.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 29 Remote Method.
Java Distributed Computing
Java Distributed Computing
Remote Method Invocation
What is RMI? Remote Method Invocation
Remote Method Invocation
Network and Distributed Programming in Java
Creating a Distributed System with RMI
Chapter 40 Remote Method Invocation
Creating a Distributed System with RMI
Overview of RMI Architecture
Remote Method Invocation
Creating a Distributed System with RMI
Chapter 46 Remote Method Invocation
Chapter 46 Remote Method Invocation
Java Remote Method Invocation
Creating a Distributed System with RMI
Overview of RMI Architecture
Presentation transcript:

1 Chapter 9 Network Programming

2 Overview Java has rich class libraries to support network programming at various levels. There are standard classes that support server and client sockets, datagram sockets, and multicast sockets. There are standard classes that support remote method invocation (RMI).

3 Overview Support for network programming is in packages such as java.net and java.rmi There are also related standard packages for security, cryptography, and server-side scripting. Additional third-party packages support technologies such as CORBA.

4 Overview Java networking reflects TCP/IP as the de facto standard for networking infrastructure, but the Java interfaces and classes abstract from low-level TCP/IP implementation details. –Classes such as InetAddress disclose the underlying IP infrastructure.

5 Overview Although network applications ultimately must be tested in a distributed environment with physically machines, initial testing can be done a standalone machine using the localhost IP address, which is in dotted-decimal notation.

6 Sockets Java supports sockets of various types. The Socket class supports TCP client sockets, that is, a socket used by a client to send requests to a server. The ServerSocket class supports TCP server sockets, that is, sockets used by a server to await client requests.

7 Sockets In a typical client/server application based on sockets, –A client opens a client Socket to the server by specifying the server’s Internet address and the port number on which the server listens. –The server’s ServerSocket listens for clients. When a client connects, the accept() method returns a reference to the client socket.

8 Sockets –The Socket has associated input and output streams through which the client and the server can exchange data, including serialized objects. –Once a transaction completes, the Socket is closed, which breaks the connection.

9 Sockets Single-threaded servers are called iterative servers. Multithreaded servers are called concurrent servers. In a typical concurrent server, the thread T that listens for clients constructs and starts separate threads to handle each client so that T can focus exclusively on listening for clients.

10 Sockets The java.net package includes a SocketImp class for applications that need to deal with firewalls, proxy servers, and the like. The Socket and ServerSocket classes have a default socket implementation that meets most needs.

11 Datagram sockets The DatagramSocket and DatagramPacket classes support IP- based networking. The MulticastSocket class supports group-based socket applications. –Multicast sockets use datagrams.

12 Datagram sockets In a typical datagram application, –The sender constructs a DatagramPacket to store the cargo bytes to be sent to a receiver. The packet is addressed to a server and sent through a DatagramSocket. –The receiver constructs a DatagramPacket to receive, through a DatagramSocket, the sent packet of bytes.

13 Serialization over sockets Serialization over sockets is attractive because of its simplicity and power. An object can serialized to an ObjectOutputStream constructed from the socket’s output stream, and then deserialized from an ObjectInputStream associated with a socket’s input stream.

14 Java Secure Sockets Extension The JSSE package supports secure Internet communications based on the Secure Sockets Layer and Transport Layer Security protocols in the TCP/IP suite. For legal reasons, the JSSE must be provided as a separate package available for free at

15 Applets An applet is a typically small program embedded in another application, generally a Web browser that provides a JVM. An applet’s host program provides an applet context in which the applet executes. An applet is generally launched from an HTML document with an APPLET tag that specifies the URL for the applet bytecodes

16 Applets At the technical level, –An applet is an object whose class descends ultimately from Applet or JApplet. –An applet is an embeddable Panel, which is a simple Container window. –An applet’s class must be public. –An applet typically overrides the inherited init, start, stop, and paint methods.

17 Applets When a Web browser downloads an applet, it typically –Invokes the init method to enable once-only initialization (e.g., setting colors, fonts, and the like) –Invokes the start method. If the applet is multithreaded, other threads can be constructed and started in this method.

18 Applets –Provides the applet real-estate in which to display itself, that is, the applet’s Panel and embedded components. –If the page that launched the applet is exited, the browser typically invokes the stop method, which then can perform appropriate cleanup operations. If the launching page is entered again, the browser again invokes start.

19 Applets Applets in the same context can communicate straightforwardly with one another by, for example, invoking one another’s accessible methods. Applets can be packaged in compressed JAR (Java Archive Files) for efficient downloading.

20 Applet security Applets typically execute under a strict security manager that prevents an applet from –Accessing the local disk to read, write, delete, or execute files. –Loading nonstandard libraries. –Opening connections to arbitrary hosts.

21 Applet security The tight applet security is sometimes described as sandbox security to suggest that an applet must “play” within a confined area from which it must not venture. An applet is allowed to open a socket to the server from which is downloaded, thus enabling socket-based communications.

22 Applets and host programs Any Java application can download an applet’s bytecodes, load the applet, and invoke the usual applet methods such as init and start. In summary, any Java application can act as an applet’s host program. –In this respect, an applet shows itself to be the bean or component that it truly is.

23 RMI Remote method invocation allows a Java program executing on one machine to invoke methods that execute on another machine. At the implementation level, an RMI client gets a reference to a remote object whose methods, exposed in an RMI interface, then can be invoked by the client.

24 RMI RMI uses serialization over sockets to handle (1) argument passing from a client invocation to a server execution and (2) a return value from a server to the invoking client. RMI technology thus leverages underlying socket technology.

25 RMI A typical RMI client –Sets its security manager to an RMISecurityManager. –Declares a reference of an interface type (e.g., Iface1 ) that the server implements. –Invokes the lookup method with the registered name of the server. –Invokes the methods declared in IFace1.

26 RMI A code segment from a sample client: System.setSecurityManager( new RMISecurityManager() ); try { Ihello hi = (Ihello) Naming.lookup( “rmi://kalinnt.cti.edu/hello” ); hi.sayHi(); hi.sayBye(); } catch( Exception e ) {/*...*/}

27 RMI A typical RMI server –Creates a public interface that extends java.rmi.Remote. Each declared method throws a RemoteException. –A public class implements the interface by appropriately defining the methods therein. The server generally extends the UnicastRemoteObject to handle argument and return value marshalling.

28 RMI –The server invokes the Naming method bind or rebind to register a server object under a symbolic name such as “HelloServer.” –The rmic utility is run on the compiled server code to generate a skeleton and a stub, which handle low-level RMI interactions. The skeleton is the server’s proxy and the stub is downloaded automatically to the client to act as the client’s proxy.

29 RMI A code segment from a sample server: public interface Ihello extends Remote { public String sayHi() throws Remote Exception; public String sayBye() throws RemoteException; }

30 RMI A code segment from a sample server: public class HelloServer extends UnicastRemoteObject implements IHello { public HelloServer throws RemoteException {/*...*/} public String sayHi() throws RemoteException {/*...*/} } // continued on next slide

31 RMI public static void main( String[ ] a ){ try { Naming.rebind( “hello”, new HelloServer() ); } catch( RemoteException e ) {/*...*/} catch( MalformedURLException e ) {/*...*/} } } // end of class

32 RMI Once the server has been rmic compiled and started, the rmiregistry utility is started on the server machine. –The registry must be active so that clients can invoke lookup to locate a specific RMI server object. The server application is then started to await clients.

33 RMI activation A standard RMI server runs continuously waiting for clients. An alternative is RMI activation, which starts a server only when a client connects to invoke a method remotely.

34 RMI and Jini RMI activation provides the infrastructure for Jini technology, which allows small digital devices (e.g., cellular phones) and software modules to be mutually accessible through a network. Jini technology extends the registry and naming services available in RMI.

35 RMI summary RMI technology leverages socket technology. Jini and Enterprise Java Bean technologies leverage RMI technology. RMI is highly flexible. For instance, an applet can be an RMI client, and a servlet can be an RMI server.

36 CORBA technology RMI requires, in effect, that the client and the server be written in the same language, Java. RMI requires that the client know the server’s URL. CORBA (Common Object Request Broker Architecture), by contrast, supports language and location transparency.

37 CORBA technology CORBA clients and servers can be written in different languages. CORBA clients can access servers through symbolic names given to the CORBA naming service. –CORBA clients need not know the server’s URL.

38 CORBA technology CORBA serves as an ORB, or object request broker. –A CORBA client requests access to an object that some CORBA server provides. At the syntax level, CORBA is quite similar to RMI: a client typically uses a reference of an interface type to invoke methods remotely.

39 CORBA technology The nonstandard org.omg package and its subpackages support CORBA under Java. CORBA is an alternative to RMI in contexts in which Java is not the exclusive language. –If Java is used on both the client and the server side, RMI has efficiency and “ease of use” advantages over CORBA.