Tuesday, February 5, 2008

Creating RPC Application

RPC stands for Remote Procedure Call which allows heterogeneous applications to communicate over a Network.

RPC can be used to communicate java applications with c++ applications. Netbula ORPC is a rich framework which allows to develop RPC applications.

First thing you need to do is creating an IDL(Interface Definition Language) file and compile it using an IDL compiler. Netbula's jrpcgen.exe is an IDL compiler which generates necessary java source codes to begin RPC application. It generate three code files:-

Interface
Server skeleton
Client stub

Here is a sample RPC IDL file.

struct cardStruct{
string cardName<>;
int cardWeight;
boolean status;
int id;
};

struct stringStruct{
string sName<>;
};

struct sArray{
stringStruct cardSet[13];

};

struct playStruct{
int cId;
cardStruct cStruct;
};

program HEARTSERV {

version HEARTSERV_V1 {

int getConnect(String)=1;
int winScore(void)=6;
sArray getCards(int)=4;
sArray getCurrentCards(void)=2;
sArray getScore(void)=3;
sArray playCards(playStruct)=5;

} = 0;

} = 1234567;

You can start building your RPC application by extending the server skeleton in server application. In client application you just need to create an instance of the client stub and call methods in that object.

When you need to run the application first thing you need to do is run the portmapper deamon which registers the processes with method names. Then run the server application and finally client application.
It's easy isn't it?