CS603 Communication Mechanisms: DCE RPC (cont.) - PowerPoint PPT Presentation

About This Presentation
Title:

CS603 Communication Mechanisms: DCE RPC (cont.)

Description:

CS603. Communication Mechanisms: DCE RPC (cont.) 23 January 2002 ... CDS pathname ... (status, 'Can't export into CDS namespace'); /* Start listening for ... – PowerPoint PPT presentation

Number of Views:156
Avg rating:3.0/5.0
Slides: 19
Provided by: clif8
Category:

less

Transcript and Presenter's Notes

Title: CS603 Communication Mechanisms: DCE RPC (cont.)


1
CS603Communication MechanismsDCE RPC (cont.)
  • 23 January 2002

2
Sample IDL formessage/reply RPC
  • / greet.idl
  • The "greet" interface. /
  • uuid(3d6ead56-06e3-11ca-8dd1-826901beabcd),
    version(1.0)
  • / import like_c_includes.idl /
  • / type declarations (typedef) /
  • interface greetif
  • const long int REPLY_SIZE 100
  • void greet(
  • in handle_t h,
  • in, string char client_greeting,
  • out, string char server_replyREPLY_SI
    ZE
  • )

3
Using defined interfaceClient
  • / greet_client.c - Client of "greet" interface.
    usage greet_client ltCDS pathnamegt/
  • include ltstdio.hgt include ltdce/rpc.hgt include
    "greet.h include "util.h"
  • Int main(int argc, char argv)
  • rpc_ns_handle_t import_context handle_t
    binding_h error_status_t status
  • idl_char replyREPLY_SIZE
  • / Start importing servers using the name
    specified on the command line. /
  • rpc_ns_binding_import_begin(rpc_c_ns_syntax_de
    fault, (unsigned_char_p_t) argv1,
  • greetif_v1_0_c_ifspec, NULL,
    import_context, status)
  • ERROR_CHECK(status, "Can't begin import")
  • / Import the first server (we could iterate
    here, but we'll just take the first one). /
  • rpc_ns_binding_import_next(import_context,
    binding_h, status)
  • ERROR_CHECK(status, "Can't import")
  • / Make the remote call. /
  • greet(binding_h, (idl_char ) "hello,
    server", reply)
  • printf("The Greet Server said s\n", reply)

4
Using defined interfaceServer
  • / greet_manager.c - Implementation of "greet"
    interface. /
  • include ltstdio.hgt
  • include "greet.h"
  • void greet(
  • handle_t h,
  • idl_char client_greeting,
  • idl_char server_reply
  • )
  • printf("The client says s\n",
    client_greeting)
  • strcpy(server_reply, "Hi, client!")

5
Using defined interfaceSetting up listener
  • / greet_server.c - usage greet_server ltCDS
    pathnamegt /
  • include ltstdio.hgt
  • include ltdce/dce_error.hgt
  • include ltdce/rpc.hgt
  • include "greet.h"
  • include "util.h"
  • Int main(int argc, char argv)
  • unsigned32 status rpc_binding_vector_t
    binding_vector
  • / Register interface with RPC runtime. /
  • rpc_server_register_if(greetif_v1_0_s_ifspec,
    NULL, NULL, status)
  • ERROR_CHECK(status, "Can't register
    interface")
  • / Use all protocol sequences that are available.
    /
  • rpc_server_use_all_protseqs(rpc_c_protseq_max_
    reqs_default, status)
  • ERROR_CHECK(status, "Can't use protocol
    sequences")
  • / Get the binding handles generated by the
    runtime. /
  • rpc_server_inq_bindings(binding_vector,
    status)
  • ERROR_CHECK(status, "Can't get bindings for
    server")

6
Using defined interfaceServer
  • / Register assigned endpoints with endpoint
    mapper. /
  • rpc_ep_register(greetif_v1_0_s_ifspec,
    binding_vector, NULL,
  • (unsigned_char_p_t) "greet server version
    1.0", status)
  • ERROR_CHECK(status, "Can't register with
    endpoint map")
  • / Export ourselves into the CDS namespace. /
  • rpc_ns_binding_export(
  • rpc_c_ns_syntax_default,
    (unsigned_char_p_t) argv1,
  • greetif_v1_0_s_ifspec, binding_vector,
    NULL, status)
  • ERROR_CHECK(status, "Can't export into CDS
    namespace")
  • / Start listening for calls. /
  • printf("Listening...\n")
  • rpc_server_listen(rpc_c_listen_max_calls_defau
    lt, status)
  • ERROR_CHECK(status, "Can't start listening
    for calls")

7
CS603Communication MechanismsJava RMI
  • 23 January 2002

8
Java RMI
  • Overview
  • Supports remote invocation of Java objects
  • Key Java Object SerializationStream objects
    over the wire
  • Language specific
  • History
  • Goal RPC for Java
  • First release in JDK 1.0.2, used in Netscape 3.01
  • Full support in JDK 1.1, intended for applets
  • JDK 1.2 added persistent reference, custom
    protocols, more support for user control.

9
Java RMI
  • Advantages
  • True object-orientation Objects as arguments
    and values
  • Mobile behavior Returned objects can execute on
    caller
  • Integrated security
  • Built-in concurrency (through Java threads)
  • Disadvantages
  • Java only
  • Advertises support for non-Java
  • But this is external to RMI requires Java on
    both sides

10
Java RMIComponents
  • Base RMI classes
  • Extend these to get RMI functionality
  • Java compiler javac
  • Recognizes RMI as integral part of language
  • Interface compiler rmic
  • Generates stubs from class files
  • RMI Registry rmiregistry
  • Directory service
  • RMI Run-time activation system rmid
  • Supports activatable objects that run only on
    demand

11
Java RMI classes
  • Java.rmi.Remote
  • Interface supporting remote objects
  • java.rmi.server.UnicastRemoteObject
  • Continuously running server
  • java.rmi.activation.Activatable
  • Server started by rmid daemon
  • java.rmi.naming
  • Lookup Returns stub given a name
  • java.rmi.RMISecurityManager
  • Validates rights to access downloaded object

12
Java RMIRegistry Operation
13
Java RMIObject Serialization
  • Key difference from DCE Can send object to be
    invoked at remote site
  • Allows objects as arguments/results
  • Mechanism Object Serialization
  • Object passed must inherit from serializable
  • Provides methods to translate object to/from byte
    stream
  • Security issues
  • Ensure object not tampered with during
    transmission
  • Solution Class-specific serializationThrow it
    on the programmer

14
Building a Java RMI Application
  • Define remote interface
  • Extend java.rmi.Remote
  • Create server code
  • Implements interface
  • Creates security manager, registers with registry
  • Create client code
  • Define object as instance of interface
  • Lookup object in registry
  • Call object
  • Compile and run
  • Run rmic on compiled classes to create stubs
  • Start registry
  • Run server then client

15
Java RMISample interface
  • import java.rmi.Remote
  • import java.rmi.RemoteException
  • public interface Hello extends Remote
  • String sayHello() throws RemoteException

16
Java RMISample Client
  • import java.rmi.Naming
  • import java.rmi.RemoteException
  • public class HelloClient
  • public static void main(String args)
  • String message "blank"
  • Hello obj null
  • try obj (Hello)Naming.lookup("//myhost/He
    lloServer")
  • message obj.sayHello()
  • System.out.println(message)
  • catch (Exception e)
  • System.out.println("HelloClient
    exception " e.getMessage())
  • e.printStackTrace()

17
Java RMIExample Server
  • import java.rmi.Naming
  • import java.rmi.RemoteException
  • import java.rmi.RMISecurityManager
  • import java.rmi.server.UnicastRemoteObject
  • public class HelloServer extends
    UnicastRemoteObject implements Hello
  • public HelloServer() throws RemoteException
    super()
  • public String sayHello() return "Hello
    World!"
  • public static void main(String args)
  • if (System.getSecurityManager() null)
  • System.setSecurityManager(new
    RMISecurityManager())
  • try HelloServer obj new HelloServer()
  • Naming.rebind("//myhost/HelloServer",
    obj)
  • System.out.println("HelloServer bound in
    registry")
  • catch (Exception e)
  • System.out.println("HelloServer err "
    e.getMessage())
  • e.printStackTrace()

18
Java RMI ExampleCompile and Run
  • javac Hello.java HelloServer.java
    HelloClient.java
  • rmic d pwd HelloServer
  • rmiregistry not in same directory
  • java -Djava.rmi.server.codebasefile///pwd/-Dj
    ava.security.policyopensocket HelloServer
  • opensocket grant permission java.net.SocketPerm
    ission "", "connect"
  • Java HelloClient
Write a Comment
User Comments (0)
About PowerShow.com