Next: , Previous: , Up: Quick Start   [Contents][Index]

3.1.1 Creating the Client

Producing a client to invoke split_number () is as simple as this:

(use-modules (rpc rpc))

(define invoke-split-number
  (make-synchronous-rpc-call 80000 0    ;; program and version
                             1          ;; procedure number
                             xdr-double ;; argument type

Again, this definition, minus the use-modules clause, can alternatively be generated by the compiler from the RPC description in XDR/RPC language (see grpc-compile):

$ grpc-compile --client < input.x > client.scm

Once this is done, invoking the procedure is as simple as this:

(invoke-split-number 3.14 #x7777 socket)

The first argument to invoke-split-number is the argument of split_number (); the second argument is a transaction ID, i.e., an arbitrarily chosen number that identifies the remote procedure call; the third argument should be an output port, typically one bound to a connection to the RPC server:

(define socket (socket PF_INET SOCK_STREAM 0))
(connect socket AF_INET INADDR_LOOPBACK 6666)

This example creates an IPv4 connection to the local host on port 6666 (see Network Sockets and Communication in The GNU Guile Reference Manual).

On success, invoke-split-number returns a two-element list where the first element corresponds to the integer_part field of the result and the second element correspond to the decimal_part field of the result, both represented as Scheme exact integers.