Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS603 Communication Mechanisms: DCE RPC (cont.) 23 January 2002.

Similar presentations


Presentation on theme: "CS603 Communication Mechanisms: DCE RPC (cont.) 23 January 2002."— Presentation transcript:

1 CS603 Communication Mechanisms: DCE RPC (cont.) 23 January 2002

2 Sample IDL for message/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_reply[REPLY_SIZE] ); }

3 Using defined interface: Client /* greet_client.c - Client of "greet" interface. usage: greet_client */ #include #include #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 reply[REPLY_SIZE]; /* Start importing servers using the name specified on the command line. */ rpc_ns_binding_import_begin(rpc_c_ns_syntax_default, (unsigned_char_p_t) argv[1], 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 interface: Server /* greet_manager.c - Implementation of "greet" interface. */ #include #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 interface: Setting up listener /* greet_server.c - usage: greet_server */ #include #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 interface: Server /* 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) argv[1], 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_default, &status); ERROR_CHECK(status, "Can't start listening for calls"); }

7 CS603 Communication Mechanisms: Java RMI 23 January 2002

8 Java RMI Overview –Supports remote invocation of Java objects –Key: Java Object Serialization Stream 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 RMI Components 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 RMI Registry Operation

13 Java RMI Object 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 serialization Throw 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 RMI Sample interface import java.rmi.Remote; import java.rmi.RemoteException; public interface Hello extends Remote { String sayHello() throws RemoteException; }

16 Java RMI Sample 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/HelloServer"); message = obj.sayHello(); System.out.println(message); } catch (Exception e) { System.out.println("HelloClient exception: " + e.getMessage()); e.printStackTrace(); } } }

17 Java RMI: Example 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 Example: Compile and Run javac Hello.java HelloServer.java HelloClient.java rmic –d `pwd` HelloServer rmiregistry & # not in same directory java -Djava.rmi.server.codebase=file:///`pwd`/ -Djava.security.policy=opensocket HelloServer –opensocket: grant { permission java.net.SocketPermission "*", "connect"; }; Java HelloClient


Download ppt "CS603 Communication Mechanisms: DCE RPC (cont.) 23 January 2002."

Similar presentations


Ads by Google