Remote Procedure Calls
In order to complete our picture of RPC processing, we'll need to review some network programming theory.
In order for two processes running on separate computers to exchange data, an association needs to be formed on each host. An association is defined as the following 5-tuple: {protocol, local-address, local-process, foreign-address, foreign-process}
The protocol is the transport mechanism (typically TCP or UDP) which is used to move the data between hosts. This, of course, is the part that needs to be common to both host computers. For either host computer, the local-address/process pair defines the endpoint on the host computer running that process. The foreign-address/process pair refers to the endpoint at the opposite end of the connection.
Breaking this down further, the term address refers to the network address assigned to the host. This would typically be an Internet Protocol (IP) address. The term process refers not to an actual process identifier (such as a Unix PID) but to some integer identifier required to transport the data to the correct process once it has arrived at the correct host computer. This is generally referred to as a port. The reason port numbers are used is that it is not practical for a process running on a remote host to know the PID of a particular server. Standard port numbers are assigned to well known services such as TELNET (port 23) and FTP (port 21).
Now we have the necessary theory to complete our picture of the RPC binding process. An RPC application is formally packaged into a program with one or more procedure calls. In a manner similar to the port assignments described above, the RPC program is assigned an integer identifier known to the programs which will call its procedures. Each procedure is also assigned a number that is also known by its caller. ONC RPC uses a program called portmap to allocate port numbers for RPC programs. It's operation is illustrated in Figure 2. When an RPC program is started, it registers itself with the portmap process running on the same host. The portmap process then assigns the TCP and/or UDP port numbers to be used by that application.
The RPC application then waits for and accepts connections at that port number. Prior to calling the remote procedure, the caller also contacts portmap in order to obtain the corresponding port number being used by the application whose procedures it needs to call. The network connection provides the means for the caller to reach the correct program on the remote host. The correct procedure is reached through the use of a dispatch table in the RPC program. The same registration process that establishes the port number also creates the dispatch table. The dispatch table is indexed by procedure number and contains the addresses of all the XDR filter routines as well as the addresses of the actual procedures.
If the discussion of the mechanisms supporting RPC sounds complex, that's because it is. Fortunately, the development of RPC applications can be greatly simplified through the use of rpcgen, the protocol compiler. rpcgen has its own input language which is used to declare programs, their procedures and the data types for the procedures' parameters and return values. This is best illustrated by an example. The source code for an average procedure is shown in Listing 1. If we store this source code in a file called avg.x and invoke rpcgen with the following command:
rpcgen avg.x
Obtain the header file avg.h shown in Listing 2. This file contains all of the function prototypes and data declarations needed for the development of our application. It will also generate three other source files:
avg_clnt.c: the stub program for our client (caller) process
avg_svc.c: the main program for our server (callee) process
avg_xdr.c: the XDR routines used by both the client and the server
To complete the application at the server end, we need code to provide the actual “smarts” required to correctly process the input data. This must be created manually. The code for the sample application presented here is shown in Listing 3. This code takes the XDR decoded array from the client and separates and averages the values. It returns the result which is then XDR encoded for transmission back to the client.
Listing 3. Server Code for Average Application
To complete the application at the client end, the input data must be packed into XDR format, so that it can be sent to the server. The client program is also generated manually and is shown in Listing 4. The Makefile shown in Listing 5 can be used to build the application.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- UX Designer
- Technical Support Rep
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Reply to comment | Linux Journal
10 hours 32 min ago - Nice article, thanks for the
21 hours 12 min ago - I once had a better way I
1 day 2 hours ago - Not only you I too assumed
1 day 3 hours ago - another very interesting
1 day 5 hours ago - Reply to comment | Linux Journal
1 day 7 hours ago - Reply to comment | Linux Journal
1 day 13 hours ago - Reply to comment | Linux Journal
1 day 14 hours ago - Favorite (and easily brute-forced) pw's
1 day 16 hours ago - Have you tried Boxen? It's a
1 day 21 hours ago





Comments
RPC
What is difference between RPC in Windows and that of LINUX?
the steps and content are
the steps and content are good..but if clear picture about the running RPC if given would have been very useful...any how thank u all the information about RPC...
About Version
I'm little bit confused with the version. If we make any changes to our program, then how we update the version. Can anyone give an example for this?
You can take the following example:
version 1: adds two floating point numbers and returns floating point result
version 2(updated): returns the rounded value
regarding the rpc
Thanks a lot for the article that you have presented. It was a lot of information. I would like to know is there any standard rpc mechanism to know about the services running over a particular machine. I need such a program to know about the processes running on a particular machine. It would be great to have your feedbacks regarding the same.
Works between ARM linux and x86 linux
Hi,
Thanks for posting the code. I tested it with server on arm-linux (Stargate xbow) and client on x86 linux. Cross compiling the code for arm-linux( just the server side files) and running /sbin/portmap on stargate will allow the rpc to register.
The program works well for C and C++ as well.
How to get ravg.c file...the
How to get ravg.c file...the makefile has no rule to get it...please excuse me if its a silly question..thanx
ravg.c is the code from
ravg.c is the code from listing 4
avg_proc.c is the code from listing 3
The code works
It is really very useful. I am a new comer in Unix [Linux], and could develop a server/client application on RPC using this code. Thank you, Ed.
I've been reading up on RPC
I've been reading up on RPC to implement it for our project, but this is the first tutorial I've found that presents it in a clear and readable manner and where the example code actually WORKS.
Thanks for a well written article, I wish there were more like it.
good introduction, with working program..
1) link of tutorial on makefile will add its value..
i find this a good one
http://www.eng.hawaii.edu/Tutor/Make/index.html
2)while excuting makefile "/n" creates problem.. i have deleted it from makefile and necessary file got generated..
3) try running server by ./avg_ser
and by client by ./ravg in seperate terminal..
4) i feel strongly that comment should be provided in avg_proc.c,ravg.c..
at last i am much thankful for this exceptionaly simple running tutorial..
Re: Remote Procedure Calls
Thanks a lot. I'm a chilean engineering student and your article has been very useful for me since it explain very clearly what RPCs are and what are they used for.