Netbula LLC                                                                   sitemapcontact us
about usproductssupportdownloadpurchase

RPC Features
RPC Example
Doc & Tutorial
RPC Forum

Writing a quote server using powerRPC 

  A typical example used to demonstrate client/server programming is a quote server, from which the client requests stock quotes across internet using TCP/IP. One can use low level socket (or Winsock or TLI) calls to transfer the data, and design some special protocol . However, such a solution contains application-specific networking code. 

With powerRPC, you write 10 lines of semi-C code to achieve the same goal in an elegant way. Basically, you declare a C function getQuote() in an interface defintion file. The server implements this function, e.g., using an embeded database query. The powerRPC compiler pasres the interface defined in the IDL file and generates a client side function defintion (client stub) getQuote() with the exact prototype as the server implementation. Internally, the client stub sends the function argument(s) to the server and waits for the result. The server receives the arguments, makes the call to the real getQuote() on behalf of the client and returns the result back to the client. From the client programmer's point of view, making a getQuote() RPC call looks no different from a call to a local function. 

OK, so much for our RPC primer, let's embark on to the journey to powerRPC programming. 

The procedure 

Step 1 

write the interface definition file quote.idl. 

%cat quote.idl

	typedef struct {             

	char Ticker[8];
	double Low, High, Close;


        interface quote {
        int getQuote( inout stkQuote* pQuote);

        } 0x12345;

Step 2 

write the server implementation file quote_impl.c . 

%cat quote_impl.c 

	#include "quote.h" 
	  /* the header file to 
		be generated by powerRPC*/

	int getQuote(stkQuote* pQuote) {

	 /* let's just return some good numbers */

	 printf("Client asked quote for %s\n", 
	 pQuote->Low = 45.2;
	 pQuote->High = 55.5;
	 pQuote->Close = 54.1;
	 return 0;



Step 3 

Run powerRPC to compile quote.idl 

%powerRPC quote.idl 

Five files will be generated after a successful compilation

File name 
used by 
The common header file for
both the client and server 
Included by the generated C code and
the server implementation and client
call files. 
The code to encode and decode
data (args and return values) to
and from the XDR format. This
allows almost abitrary C data types
to be tranfered correctly and
by both the client and server 
The server dispatch code. When
a call is received from the client,
the server unpacks the arguments
and call the function implementation. 
server only 
The client stub. Defines the getQuote()
stub call. Inside it, the args are sent to
the server and the client is blocked
waiting for the results.
client only 
quote.mak The makefile. Default target will
compile both the server and client.
May need user custmization.
the lucky programmer 

Step 4 

Code a client that calls getQuote() RPC. 

%cat quote_call.c 

  #include "quote.h"
   int main(int argc, char** argv) {
	stkQuote quote;

	if(argc<3) {
	 printf("Usage: %s serverhost tikcer\n", 
	if(quote_bind(argv[1],0,0,0) == NULL) {
	   printf("Fail connecting to server on %s\n",
	 strcpy(quote.Ticker, argv[2]);
	 if(getQuote("e)) {
	 printf("Fail getting quote for %s\n",
	 } else {
	 printf("Low = %f, High =%f, Close = %f",
	       quote.Low, quote.High, quote.Close);
	 return 0;

Step 5 

The last step--compile and run 

% make -f quote.mak 

This should compile the server quoteserv amd the client quoteclnt. Now we can test our quote client/server. 

% quoteserv& 

% quoteclnt <server_host> NTBL 


Now, you see how easy to use powerRPC  to write cient/server applications . You may started guessing about the meaning of words such as inout used in the IDL, and generated functions such as quote_bind(), quote_unbind(), etc. But you have only see a tiny demo of the power of powerRPC. For more interesting examples, please take a look at the online tutorial, where you can find code for a file server. 

| Home | Products | Support | Download | Purchase | Site Map | Contact Us |
Copyright © 2000, Netbula LLC, All Rights Reserved.


Anyemail Anyboard JRPC ONC RPC PowerRPC