7 Nov '14

Anupa Manipal

A professional Software Developer in VB.NET - SQL Server and learner of PHP. Expertise in implementation of various projects including designing, development, coding and implementation of software applications.

0 Shares

Implemention RPC using java

IMPLEMENTATION OF RPC

AIM:

To write a program for implementing RMI/RPC using java

ALGORITHM:

1) Create a source code for AddServer, AddClient, AddServerImpl, AddServerIntf

2) Compile the source code

3) Generate the stubs and skeletons using rmic command rmicAddServerImpl

4) Start the rmiregistry start rmiregistry

5) Start the server java Server

6) Start the client Java client 9 8

 

PROGRAM:

AddServer

import java.net.*;

importjava.rmi.*;

public class AddServer

{

public static void main(String args[])

{

try

{

AddServerImpladdServerImpl=new AddServerImpl();

Naming.rebind(“AddServer”,addServerImpl);

}

catch(Exception e)

{

System.out.println(e);

}

}

}

AddClient

importjava.rmi.*;

public class AddClient

{

public static void main(String args[]) throws Exception

{

String addServerURL = “rmi://localhost/AddServer”;

AddServerIntfaddServerIntf = (AddServerIntf)Naming.lookup(addServerURL);

System.out.println(“The First Number is : ” + args[0]);

int d1 = Integer.valueOf(args[0]);

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

int d2 = Integer.valueOf(args[1]);

System.out.println(“The Sum is : ” + addServerIntf.add(d1,d2));

}

}

ADDSERVERIMPL:

importjava.rmi.*;

importjava.rmi.server.*;

public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf

{

publicAddServerImpl() throws RemoteException

{}

publicint add(int d1,int d2) throws RemoteException

{

int d3 = d1 + d2;

return d3;

}

public static void main(String args[])throws Exception

{

AddServerImplImpl = new AddServerImpl();

Naming.rebind(“AddServer”, Impl);

System.out.println(“Registered is Done !”);

}

}

ADDSERVERINTF:

importjava.rmi.*;

public interface AddServerIntf extends Remote

{

int add(int d1,int d2) throws RemoteException;

}

 

OUTPUT:

E:\java>javac AddServerIntf.java

E:\java>javac AddServerImpl.java

E:\java>javac AddClient.java

E:\java>javac AddServer.java

E:\java>rmic AddServerImpl

E:\java>start rmiregistry

E:\java>java AddServer

E:\java>java AddClient 4 5

The First Number is : 4

The Second Number is : 5

The Sum is : 9

RESULT:

The program for implementation of RMI/RPC was successfully executed and verified successfully

About Anupa Manipal

A professional Software Developer in VB.NET - SQL Server and learner of PHP. Expertise in implementation of various projects including designing, development, coding and implementation of software applications.

Related Posts

Leave a Reply