190 likes | 590 Views
9/20/2012. 2. What is rpcgen. A compiler that assists programmers in writing RPC applications simply and directlyAccepts a definition file (the .x' file) written in RPC language (similar to C)Minimally produces the following C language output files:Client routine stub fileServer skeletonXDR R
E N D
1. RPC Tutorial using rpcgenon NJITs AFS System Steven Brown
2. 9/20/2012 2 What is rpcgen
A compiler that assists programmers in writing RPC applications simply and directly
Accepts a definition file (the .x file) written in RPC language (similar to C)
Minimally produces the following C language output files:
Client routine stub file
Server skeleton
XDR Routines for parameters and results
Header file for common definitions
3. 9/20/2012 3 Why use rpcgen
Reduces development time on coding and debugging low-level routines
Especially useful for writing the XDR routines necessary for converting procedure arguments and results into their network format and vice-versa
rpcgen can be used as a starting point and then rewrite as appropriate
4. 9/20/2012 4 How to use rpcgen
Log on to one of public AFS systems AFS[1-36,49-59].njit.edu
Navigate to the directory where your interface definition file (the .x file) is located (See Appendix for an example definition file)
Run the following command: rpcgen options infile
Review the files that are created in the directory
5. 9/20/2012 5 rpcgen Options -aGenerates all files including client and server sample files
-cCompiles definition file into XDR routines defaulting to stdout
-CUsed to generate header and stub files that will work with ANSI C compilers
-lCompiles definition file into client side stubs defaulting to stdout
6. 9/20/2012 6 rpcgen Options -mCompiles definition file into server side stubs defaulting to stdout. This also stops a main routine from being created. Therefore allowing the user to create their own
-NAllows procedures to have multiple arguments and uses C style parameter passing
-oUsed to specify the output file for those arguments that default output to stdout
7. 9/20/2012 7 rpcgen Options -ScCompiles definition file into sample client code defaulting to stdout.
-SmCompiles definition file into sample Makefile code defaulting to stdout.
-SsCompiles definition file into sample server code defaulting to stdout.
-YDirectory where rpcgen starts its search for the C preprocessor
8. 9/20/2012 8 XDR XDR language is similar to C.
Data is represented in the interface definition file using XDR. Utilizing the power of rpcgen this file will be used to create C type definitions in the output files.
Upon executing rpcgen you will notice a file infile_xdr.c created which represents the data defined in the interface definition file.
The following slides outline the definition types allowed in XDR with an example of each.
9. 9/20/2012 9 XDR Definition Types enumenum colortype {
RED = 0,
GREEN = 1,
BLUE = 2
};
structstruct coord {
int x;
int y;
};
typedeftypedef string fname_type<255>;
constconst DOZEN = 12;
10. 9/20/2012 10 XDR Definition Types programprogram GETHOST_PROG {
version GETHOST_VERS {
string GETHOSTPROC( string ) = 1 ;
} = 1 ;
} = 0x35238904 ; declarationcolortype color
unionunion read_result switch (int errno) {
case 0:
opaque data[1024];
default:
void;
};
11. 9/20/2012 11 Separate Client and Server After compiling the server files created by rpcgen move the server file to a remote machine (i.e., another AFS machine).
On this machine run the server in the background with the following command: server &
On the original machine run the client with the following command: client remoteAFSmachinename
12. 9/20/2012 12 Appendix
13. 9/20/2012 13 Example Definition File (.x) /* maximum length of a directory entry */
const MAXNAMELEN = 255;
/* a directory entry */
typedef string nametype<MAXNAMELEN>;
/* a link in the listing */
typedef struct namenode *namelist;
/* A node in the directory listing */
struct namenode {
nametype name; /* name of directory entry */
namelist next; /* next entry */
};
14. 9/20/2012 14 Example Definition File (.x) /* The result of a READDIR operation. */
union readdir_res switch (int errno) {
case 0:
namelist list; /* no error: return listing */
default:
void; /* error occurred: nothing to return */
};
/* The directory program definition */
program DIRPROG {
version DIRVERS {
readdir_res
READDIR(nametype) = 1;
} = 1;
} = 0x20000076;
15. 9/20/2012 15 Shutting Down the Server Your server will run until NJIT stops it unless you tell it to stop.
Please be polite and shut it down. The command is
rpcinfo d [program number] [version number]
Show this command on your screen shot for the server.
16. 9/20/2012 16 Hints Need -lnsl switch on AFS gnu C++ compiler to obtain networking functions
gnu compiler does not recognize // comments, you have to substitute /* */
RPC uses string for array of char
rpcgen -N -a is needed to generate client and server files as well
If you are mising rpc/rpc.h, include rpc/pmap_prot.h
Types not defined in RPC can be passed inside a struct
17. 9/20/2012 17 Troubleshooting These are listed on the previous slide, but most problems are related to one of them, so they are repeated here:
Use gcc -lnsl on AFS to obtain networking functions
rpcgen -N -a to generate client and server files (you must compile a .x file, not .c)
18. 9/20/2012 18 Other Troubleshooting rpcinfo -p will show you what RPC programs are registered
If you get:
RPC: Program not registered
you probably did not compile your *_xdr.c file, or perhaps you ran the client before running the server.
Connect to AFS using SSH. See http://web.njit.edu/~gblank/Help.ppt if you need help with this.
19. 9/20/2012 19 Checking the Server The RPC server will usually run in the background by default (you should not need &).
You may not have permission to write to the console on a server. The cleverest workaround I saw for this was to use the ps command to show that the server was running. (Server was called echo_server):
ps aef | grep i echo_server