Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Programming: Advanced Topics 1 Networking Programming Chapter 11.

Similar presentations


Presentation on theme: "Java Programming: Advanced Topics 1 Networking Programming Chapter 11."— Presentation transcript:

1 Java Programming: Advanced Topics 1 Networking Programming Chapter 11

2 Java Programming: Advanced Topics 2 Objectives Perform network I/O using the core classes in the package java.net Write programs that establish connections to URLs and perform stream I/O between URLs Read and write data to local and remote sites using TCP/IP sockets and datagram sockets

3 Java Programming: Advanced Topics 3 Objectives (Cont.) Use Remote Method Invocation (RMI) to develop classes of objects that are accessible from a server Learn the steps involved in compiling and deploying an application that uses RMI

4 Java Programming: Advanced Topics 4 Objectives (Cont.) Be introduced to the Java Naming and Directory Interface (JNDI) Discover the relationship between CORBA, RMI-IIOP, and the Java Interface Definition Language (IDL)

5 Java Programming: Advanced Topics 5 Introduction The Java platform includes a package java.net to perform input and output (I/O) operations over the network Core classes of the java.net package support URLs, TCP/IP sockets, or datagram sockets

6 Java Programming: Advanced Topics 6 Working with URLs URLs begin with a protocol specification followed by a colon and two forward slashes (://) and the host name, along with optional file and port information To exchange information with a URL, you must create a URLConnection by calling the method openConnection for a URL

7 Java Programming: Advanced Topics 7 The Use of the URL and URLConnection Objects

8 Java Programming: Advanced Topics 8 The Use of the URL and URLConnection Objects (Cont.)

9 Java Programming: Advanced Topics 9 Working with URLs (Cont.) Uniform Resource Identifier (URI) technology has become commonly used in technical specifications in place of the term URL The class java.net.URI contains a method, toURL, which can be used to construct a URL object from a URI object

10 Java Programming: Advanced Topics 10 Working with Sockets Socket: an abstraction of the end points of connections between processes or applications The Java platform supports two types of sockets: –TCP/IP –datagram

11 Java Programming: Advanced Topics 11 TCP/IP Sockets A TCP/IP socket is connection-oriented Create a Socket object, ask the socket for its input stream and output stream To perform stream I/O to and from a TCP/IP socket, use the methods Socket.getInputStream and Socket.getOutputStream Use the ServerSocket class to create the server side of a TCP/IP socket

12 Java Programming: Advanced Topics 12 Datagram Sockets Datagram sockets send packets that contains information that identifies the network destination in addition to the content of your message The class DatagramPacket represents these packets The User Datagram Protocol (UDP) used by these sockets makes no attempt to recover from lost or damaged packets

13 Java Programming: Advanced Topics 13 An Example Datagram Socket Server Program

14 Java Programming: Advanced Topics 14 An Example Datagram Socket Server Program (Cont.)

15 Java Programming: Advanced Topics 15 An Example Datagram Socket Server Program (Cont.)

16 Java Programming: Advanced Topics 16 An Example Datagram Socket Client Program

17 Java Programming: Advanced Topics 17 An Example Datagram Socket Client Program (Cont.)

18 Java Programming: Advanced Topics 18 Remote Method Invocation Remote Invocation Method (RMI) is a technology that allows programmers to call directly the methods of Java objects that reside on other systems Client programs use Object Request Brokers (ORBs) to obtain references to these remote objects Marshaling: the technique used to forward the parameters to the remote object

19 Java Programming: Advanced Topics 19 Remote Method Invocation Stub classes act as local surrogates for remote objects to provide access to the remote objects Skeleton classes marshal and unmarshal parameters and return values between the stub and the remote object On the remote system, a skeleton object receives this byte stream and uses a technique called unmarshaling to deserialize the contents of the parameter list

20 Java Programming: Advanced Topics 20 Flow of a Remote Method Call

21 Java Programming: Advanced Topics 21 Developing a Remote Class of Objects The Remote interface is a marker interface To make an interface available remotely via RMI, it should extend the java.rmi.Remote All methods in the interface must indicate that they might throw a java.rmi.RemoteException

22 Java Programming: Advanced Topics 22 Remote Interface

23 Java Programming: Advanced Topics 23 Developing an RMI Server Class

24 Java Programming: Advanced Topics 24 Developing an RMI Server Class (Cont.)

25 Java Programming: Advanced Topics 25 Developing an RMI Client Class

26 Java Programming: Advanced Topics 26 Developing an RMI Client Class (Cont.)

27 Java Programming: Advanced Topics 27 Running the Server and Client Programs Compile server and client files using the javac compiler Create the stub and skeleton classes by using the rmic command Start the RMI registry program by typing: rmiregistry Start the server program and supply the codebase for the stub and skeleton files Start the client program

28 Java Programming: Advanced Topics 28 JNDI Sun developed the Java Naming and Directory Interface (JNDI) JNDI is not itself a naming or directory service, but is a unified interface to multiple naming and directory services that already exist for enterprise development

29 Java Programming: Advanced Topics 29 JNDI Packages

30 Java Programming: Advanced Topics 30 JNDI Packages (Cont.)

31 Java Programming: Advanced Topics 31 Corba, RMI-IIOP, and IDL Common Object Request Broker Architecture (CORBA) is a generic architecture for defining and using remote objects A consortium of companies, known as the Object Management Group (OMG), developed the CORBA standard CORBA ORBs use Internet Inter-ORB Protocol (IIOP)

32 Java Programming: Advanced Topics 32 Corba, RMI-IIOP, and IDL (Cont.) The interfaces of CORBA objects are defined using a language called Interface Definition Language (IDL) Java platform SDK provides a tool called idlj that generates the Java bindings for the specified IDL file

33 Java Programming: Advanced Topics 33 Summary The java.net package supports network programming The core classes of the java.net package support URLs, TCP/IP sockets, or datagram sockets To exchange information with a URL, you must create a URLConnection object TCP/IP sockets are connection-oriented, and datagram sockets use packets

34 Java Programming: Advanced Topics 34 Summary (Cont.) Remote Invocation Method (RMI) is a technology that allows programmers to call directly the methods of Java objects that reside on other systems The Java Naming and Directory Interface (JNDI) is a unified interface to multiple naming and directory services that already exist for enterprise development Common Object Request Broker Architecture (CORBA) is a more generic architecture for defining and using remote objects


Download ppt "Java Programming: Advanced Topics 1 Networking Programming Chapter 11."

Similar presentations


Ads by Google