LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-11-2003, 11:58 PM   #1
ratheesh
LQ Newbie
 
Registered: Nov 2003
Posts: 7

Rep: Reputation: 0
rpc help


hi ,
i am new to rpc programming. i am doing programming in c on linux clusters.it is actually in system side. i need to run c programs in different nodes from one node(master). i read rpcgen.pdf and rpc.pdf. but this will not gave me an idea to start writting rpc programs.please tell me how can i solve this problem.
 
Old 12-12-2003, 09:27 AM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
I'll give you an example for math functions that can be called via RPC.

First you need to create a file that describes the RPC functions. Here's mycal.x:

Code:
struct mycal_in {
   double arg1;
   double arg2;
};

struct mycal_out {
   double res1;
};

program MYCAL_PROG {
   version MYCAL_VERS {
      mycal_out ADDPROC(mycal_in) = 1;
      mycal_out SUBTRACTPROC(mycal_in) = 2;
      mycal_out MULTIPLYPROC(mycal_in) = 3;
      mycal_out DIVIDEPROC(mycal_in) = 4;
   } = 1;
} = 0x53778892;
You use rpcgen to compile this and produce mycal.h (among others) that is included in your client and server. You'll have to look at mycal.h to see the prototypes for the functions that you have to implement.

Code:
rpcgen -N -C mycal.x
You'll have other outputs from rpcgen that will need to be compiled and linked into your application: mycal_xdr.c and mycal_svc.c need to be compiled and linked into your server program whereas mycal_xdr.c and mycal_clnt.c need to be compiled and linked into your client program.

Now write the functions for the server. Here's mycal_server.c:

Code:
#include "mycal.h"
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <signal.h>

mycal_out *
addproc_1_svc(mycal_in arg1, struct svc_req *rqstp)
{
	static mycal_out  result;

	/*
	 * insert server code here
	 */

	result.res1 = arg1.arg1 + arg1.arg2;

	return (&result);
}

mycal_out *
subtractproc_1_svc(mycal_in arg1, struct svc_req *rqstp)
{
	static mycal_out  result;

	/*
	 * insert server code here
	 */

	result.res1 = arg1.arg1 - arg1.arg2;

	return (&result);
}

mycal_out *
multiplyproc_1_svc(mycal_in arg1, struct svc_req *rqstp)
{
	static mycal_out  result;

	/*
	 * insert server code here
	 */

	result.res1 = arg1.arg1 * arg1.arg2;

	return (&result);
}

mycal_out *
divideproc_1_svc(mycal_in arg1, struct svc_req *rqstp)
{
	static mycal_out  result;

	result.res1 = 0;

	if( arg1.arg2 ) {
	  result.res1 = arg1.arg1 / arg1.arg2;
        }

	return (&result);
}
Finally you need to write the client that calls these functions. It too will have mycal.h #included. My C++ program implemented a parser for an LL(1) grammar that recognizes valid arithmetic expressions, constructed a parse tree of the expressions, then traversed the parse tree to evaluate the expressions. Evaluating an expression involves making calls to the RPC math functions. Here's one method used in the expression evaluation:

Code:
double ParseTree::doDivide( double a, double b )
{
  CLIENT*  client;
  mycal_in   in;
  mycal_out* out;
  double   result = 0;


  if( b != 0 ) {

     in.arg1 = a;
     in.arg2 = b;
	
     client = clnt_create(hostname, MYCAL_PROG, MYCAL_VERS, "tcp");
	
     if( client == NULL ) {
        throw ParseTreeError( "Failed to create RPC client for divide()." );
     }

     out = divideproc_1( in, client );

     if( out == NULL ) {
        throw ParseTreeError( "Failed RPC to divide()." );
     }

     clnt_destroy( client );
     result = out->res1;
  }
  else{
     throw ParseTreeError("Divide by zero not allowed.");
  }

  return( result );
}
If you want all of my code, send me an email and I'll send you everything I have.
 
Old 03-07-2004, 11:00 PM   #3
Melvin3
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
Hi, Mr eric.r.turner,

I am now starting on a project on rpc programming, so would you mind if I can have your codes for my reference and learning.
Please kindly email your codes to the following email address: nmak_@hotmail.com
Please help, your help will be greatly appreciated. Thank you in advance.

Regards,
Melvin
 
Old 03-22-2004, 11:35 PM   #4
alvinokh
LQ Newbie
 
Registered: Mar 2004
Distribution: Redhat
Posts: 1

Rep: Reputation: 0
Hi eric.r.turner,

I'm currently doing an assignment on RPC. If you still have it, do you mind sending me your code for rpc? I will greatly appreciate your code for reference. Thanks.

email: alvinokh@hotmail.com

Regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NFS RPC: Port mapper failure - RPC: Unable to receive KEJP Linux - Networking 6 12-18-2006 02:14 AM
mountd time out: "mount_nfs: bad MNT RPC: RPC: Timed out" on client brush Debian 1 10-15-2006 02:01 PM
rpc.lockd & rpc.statd twantrd Linux - General 1 05-21-2005 09:24 AM
About RPC rajesh_b Programming 1 01-07-2005 10:32 AM
Unmounting NFS filesystems: Cannot MOUNTPROG RPC: RPC ErnstVikenstein Linux - General 4 05-31-2003 12:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration