Saturday 20 April 2013

Remote procedure call.



EXPERIMENT NO.6

AIM:
Program  on Remote procedure call.

THEORY:
            RPC is an interprocess communication technique that allows client and server software to communicate.
            An RPC is initiated by the client, which sends a request message to a known remote server to execute a specified procedure with supplied parameters. The remote server sends a response to the client, and the application continues its process.


Sequence of events during a RPC

1.     The client calls the client stub. The call is a local procedure call, with parameters pushed on to the stack in the normal way.
2.     The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling.
3.     The kernel sends the message from the client machine to the server machine.
4.     The kernel on the server machine passes the incoming packets to the server stub.
5.     Finally, the server stub calls the server procedure. The reply traces the same steps in the reverse direction.
         
            The RPC tools make it appear to users as though a client directly calls a procedure located in a remote server program. The client and server each have their own address spaces; that is, each has its own memory resource allocated to data used by the procedure. The following figure illustrates the RPC architecture.

            As the illustration shows, the client application calls a local stub procedure instead of the actual code implementing the procedure. Stubs are compiled and linked with the client application. Instead of containing the actual code that implements the remote procedure, the client stub code:
·       Retrieves the required parameters from the client address space.
·       Translates the parameters as needed into a standard NDR format for transmission over the network.
·       Calls functions in the RPC client run-time library to send the request and its parameters to the server.
The server performs the following steps to call the remote procedure.
1.    The server RPC run-time library functions accept the request and call the server stub procedure.
2.    The server stub retrieves the parameters from the network buffer and converts them from the network transmission format to the format the server needs.
3.    The server stub calls the actual procedure on the server.
            The remote procedure then runs, possibly generating output parameters and a return value. When the remote procedure is complete, a similar sequence of steps returns the data to the client.
1.    The remote procedure returns its data to the server stub.
2.    The server stub converts output parameters to the format required for transmission over the network and returns them to the RPC run-time library functions.
3.    The server RPC run-time library functions transmit the data on the network to the client computer.
            The client completes the process by accepting the data over the network and returning it to the calling function.
1.    The client RPC run-time library receives the remote-procedure return values and returns them to the client stub.
2.    The client stub converts the data from its NDR to the format used by the client computer. The stub writes data into the client memory and returns the result to the calling program on the client.
3.    The calling procedure continues as if the procedure had been called on the same computer.
            The run-time libraries are provided in two parts: an import library, which is linked with the application and the RPC run-time library, which is implemented as a dynamic-link library (DLL).
            The server application contains calls to the server run-time library functions which register the server's interface and allow the server to accept remote procedure calls. The server application also contains the application-specific remote procedures that are called by the client applications.




CONCLUSION:
            Remote procedure call is an inter-process communication technique initiated by the client, which sends a request message to a known remote server to execute a specified procedure with supplied parameters on remote server.
















PROGRAM:

import java.rmi.*;
public interface AddServerintf extends Remote
{
                double add(double d1,double d2)throws Remoteexceptions;
}

                                                                AddServerimpl.java

import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends Unicastremoteobject implements AddServerIntf
{
                public AddServerimpl()throws RemoteException
                {
                }

                public double add(double d1. Double d2)throws Remote Exception
                {
                return d1+d2;
                }
}
                                                               AddServer.java

import java.net.*;
import java.rmi.*;
public class AddServer
{
                public static void main(String args[])
                {
                                try
                                {
                                                AddServerImpl addServerImpl=new AddServerImpl();
                                                Naming.rebind(“AddServer”, addServerImpl);
                                }
                                catch(Exception e)
                                {
                                                System.out.println(“Exception:”+e);
                                }          
                }

}

                                                AddClient.java

import java.rmi.*;

public class AddClient
{
                public static void main(String args[])
                {
                                try
                                {
                                                String addServerURL=”rmi://”+args[0]+”/Addserver”;
                            AddServerIntf addServerIntf=(AddServerintf)Naming.lookup(addServerURL);

                                                System.out.println(“The first number is:”+args[1]);

                                                Double d1+double.valueof(args[1]).doubleValue();

                                                System.out.println(“The second number is:”+args[21]);

                                                Double d2=Double.valueOf(args[2]).doublevalue();

                                }

                                catch(Exception e)

                                {

                                                System.out.println(“Exception:”+e);    

                                }

                }          

}

OUTPUT:

Rmic AddServerImpl

Start rmiregistry

Java AddServer

Java AddClient 127.00.1 8 9

The first number is: 8

The second number is: 9

The sum is: 17

Objective Questions:
1.What is Remote Procedure Call (RPC)?
2.Which of the following statements about a remote procedure call is true?
(A) It is used to call procedures with addresses that are farther than 162 bytes away.
(B) It cannot return a value.
(C) It cannot pass parameters by reference.
(D) It cannot call procedures implemented in a different language.
(E) It is used to call procedures at an outer nesting level.

1 comment:

  1. Very helpful post. With the help of this article I became familiar with the working of "Remote procedure Call". You have provided the complete steps and explained it using an example. Thank you very much!
    electronic signature

    ReplyDelete