Cs603 communication mechanisms dce rpc cont
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

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


  • 74 Views
  • Uploaded on
  • Presentation posted in: General

CS603 Communication Mechanisms: DCE RPC (cont.). 23 January 2002. 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

Download Presentation

CS603 Communication Mechanisms: DCE RPC (cont.)

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cs603 communication mechanisms dce rpc cont

CS603Communication Mechanisms:DCE RPC (cont.)

23 January 2002


Sample idl for message reply rpc

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_reply[REPLY_SIZE]

);

}


Using defined interface client

Using defined interface:Client

/* greet_client.c - Client of "greet" interface. usage: greet_client <CDS pathname>*/

#include <stdio.h> #include <dce/rpc.h> #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);

}


Using defined interface server

Using defined interface:Server

/* greet_manager.c - Implementation of "greet" interface. */

#include <stdio.h>

#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!");

}


Using defined interface setting up listener

Using defined interface:Setting up listener

/* greet_server.c - usage: greet_server <CDS pathname> */

#include <stdio.h>

#include <dce/dce_error.h>

#include <dce/rpc.h>

#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");


Using defined interface server1

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");

}


Cs603 communication mechanisms java rmi

CS603Communication Mechanisms:Java RMI

23 January 2002


Java rmi

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.


Java rmi1

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


Java rmi components

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


Java rmi classes

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


Java rmi registry operation

Java RMIRegistry Operation


Java rmi object serialization

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


Building a java rmi application

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


Java rmi sample interface

Java RMISample interface

import java.rmi.Remote;

import java.rmi.RemoteException;

public interface Hello extends Remote {

String sayHello() throws RemoteException;

}


Java rmi sample client

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/HelloServer");

message = obj.sayHello();

System.out.println(message);

} catch (Exception e) {

System.out.println("HelloClient exception: " + e.getMessage());

e.printStackTrace();

} } }


Java rmi example server

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();

} } }


Java rmi example compile and run

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


  • Login