Running CERN RPC under Unix

# Running RPC under Unix

See also: Building an application under unix, Installing RPC under unix .

Under Berkley unix, DEC Ultrix or equivalent, the RPC system can communicate over TCP/IP. For raw ethernet or RS232 (v24) working, routines to send and receive packets (characters) would have to be written for your system. TCP is recommended. See the section on TCP for details of addressing. The shell environment (see setenv, printenv commands) is used to define rpc addresses. The RPC compiler is available to run in these environments.

Support in this environment is currently for C compatible software, FORTRAN can be made be avialable if required. The stubs should be generated using GenericC or FORTRAN options of the compiler, and then compiled using the resident C compiler. They must be linked with the rpclib.o module and rpc_rts_for if in FORTRAN.

The stubs must be initialised (See Initialization ) by calls to open_xxx and attach_xxx in the client and server programs respectively.

## Defining addresses

See the earlier sections in this chapter for the format of RPC addreses.

The setenv command must be used (under csh) or and equate (a=b) syntax under the shell 'sh'. For example,

            setenv TESTPACKAGE CERNVAX:777.TCP

            setenv RPC_CLIENT_NAME '*:777.TCP'

Note that in the last example, the single quotes were necessary to stop the shell interpreting the "*" character.

## Example

Imagine we have written a file server called "FILER". The interface is described by a file "filer.rpc". The simple IN variables are passed by value as in normal in C. The client application program is called myclient.c and the filer server itself is filer.c.

First, we generate the server program. Here, filer.c contains a simple main program which calls attach_filer() to initialise the stub, and then rpc_loop_server(..) to run the server. It also, of course, contains the file access routines themselves.

    	rpcc -sgenericc=filer_server_stub.c -byvalue filer.rpc
    	cc -o filer filer.c filer_server_stub.c rpcrts.o ts.o
    	chmod +x filer

Next, we generate the client. The client in this example has a call to open_filer() before it uses any remote routines.

    	rpcc -cgenericc=filer_client_stub.c -byvalue filer.rpc
    	cc -o myclient myclient.c filer_client_stub.c rpcrts.o ts.o
    	chmod +x myclient

Now we run the server, asking it to wait for any connections to TCP port 1789:

    	setenv RPC_CLIENT_NAME '*:1789.TCP'
    	filer &

We can leave that running and go start the client:

    	setenv FILER mynode:1789.TCP
    	myclient

where mynode is the internet name of the node on which the server is running. Here, the port number was chosen to be random but greater than 1024. See the section on TCP addressing.

## Diagnostic trace output

If there is a problem, the RPC sytem will normally print an error message. If this is insufficient to determine what has gone wrong, then the same program may be run with the runtime trace turned on. This is done by setting the environment variable RPC_TRACE_FLAG to the name of the file to be used. For example,

    	setenv RPC_TRACE_FLAG rpc.trace
    or
    	setenv RPC_TRACE_FLAG /dev/tty

Trace information will be appended to the given file. To turn the trace back off, the command is

    	unsetenv RPC_TRACE_FLAG

(Don't use setenv RPC_TRACE_FLAG /dev/null which will just slow down the RPC system to no purpose)