[prev] [up] [next]

SunRPC Remote Procedure Call Implementation

Overview

This framework implements the complete SunRPC Remote Procedure Call protocol, including both client and server modes, an IDL parser, XDR marshalling, a portMapper, NFS server and NFS-mount implementations, and a bunch of demo applications.

Documentation

See the README and documentation protocols of the various SunRPC classes.

DemoServer Example

A minimal RPC setup is found in the two classes DemoServer and DemoClient;

Server

The DemoServer provides a single rpc-procedure, "showOnTranscript", expecting a string argument, which is displayed on the transcript.

The range of ip-port numbers which the server uses is defined by the following method:

    portNumbers
	^ #( 44400 to: 44499 )
this lets the server process choose any free port in the given range. Notice that clients of the server need not know the concrete port number, as all rpc servers register themselfes at the portmapper. The portmapper maps the programs number (as specified in its xdr definition) to the port number on which the server sits.
Portmapper is usually already installed on your system (on all unix systems); however, a smalltalk implementation of it is also part of the ST/X distribution.

The interface is defined in the classes xdr method, which is defined as:

    xdr
	^ '

	typedef string stringArg<>;

	program DEMO {
		version DEMOVERS {
			void
			null(void) = 0;

			boolean
			showOnTranscript(stringArg) = 1;
		} = 1;
	} = 200199;
    '
Notice, that all RPC servers should provide the "null" procedure, which can be used for connectivity testing.
However, the programmer is not required to implement this method (it is inherited, from the DemoServers superclass: RPCServer.

The implementation of the showOnTranscript is simple:

    showOnTranscript:argVector
	Transcript showCR:(argVector at:1).
	^ true.
Thats all - the server is started by evaluating:
    SunRPC::DemoServer start
After that, you should find the server process in the ProcessMonitor, as it waits for incoming connections.
Also, you can should find the server registered in the portmapper, by executing (on the shell level) the following command (as root on most systems) :
    # rpcinfo -p
the programnumber (20199) should be in the list.

Client

Now, a client could be implemented in any programming language with RPC support (notice, that RPC implementations are available for virtually all programming languages).

A smalltalk client is especially simple; only two methods are required to implement a DemoClient: xdr (on the class side) to define the interface, and a call-wrapper.

The interface definitionis the same as the servers definition, therefore, xdr is defined in DemoClient as:

    xdr
	^ DemoServer xdr
the call wrapper is:
    showOnTranscript:aString
	|reply|

	reply := self operation:#showOnTranscript argument:aString.
	^ reply

Now, a client request can be sent with:

    |demoClient|

    demoClient := SunRPC::DemoClient toHost:'localhost'.
    demoClient showOnTranscript:'hello world'.

No Warranty

This goody is provided AS-IS without any warranty whatsoever.

Origin/Authors


Claus Gittinger


Copyright © 2002 eXept Software AG

<info@exept.de>

Doc $Revision: 1.5 $