Specifications
rpc(address, function, args…) – Remote Procedure Call (RPC)
Call a Remote Procedure (make a Remote Procedure Call, or RPC), using unicast messaging. A
special packet will be sent to the node specified by parameter address, asking that remote node to
execute the function specified by parameter function. The specified function will be invoked with the
parameters specified by args, if any args are present.
For example, rpc('\x12\x34\x56', 'writePin', 0, True) will ask the node at address
12.34.56 to do a writePin(0, True).
rpc('\x56\x78\x9A', 'reboot') will ask the node at address 56.78.9A to do a reboot().
This function normally returns True. It returns False only if it was unable to attempt the Remote
Procedure Call (for example, if the node is low on memory, or the RPC was too large to send).
If this function returns True, it does not mean your RPC request was successfully sent and received.
(SNAP will give up after a programmable number of retries, which defaults to 8.) If you need
confirmation that the remote node executed your request, it needs to come as an RPC call from that
remote node. Refer to the callback() function for one method of doing this.
It is important that you provide the correct number of arguments for the function you are calling. The
tooltip help that displays in Portal shows three arguments for this function (address, function, args),
but the remote function you are calling might require more or fewer arguments than the one specified.
A remote call of rpc('\x56\x78\x9A', 'reboot') will ask the node at address 56.78.9A to do a
reboot(), while rpc('\x56\x78\x9A', 'reboot', '') will not work because the receiving
node will not find a built-in function with a matching function signature. If the remote function you
are calling does not require any arguments, you should omit the third “args” argument of the RPC
function. If the remote function requires more arguments, you should include them, too.
Built-in functions in nodes can always be called interactively from Portal, but if you are invoking a
built-in function in a node from a script in another node, the node on which the function is being called
must also have a script loaded, even if it is just an empty script. In the act of loading the script file,
Portal establishes a function table in the node that must be present before the remote node can find
built-in functions to run from an RPC call.
rpcSourceAddr() – Who made this Remote Procedure Call?
If a function on a node is invoked remotely (via RPC), then the called function can invoke function
rpcSourceAddr() to find out the Network Address of the node which initiated the call. (If you call this
function when an RPC is not in progress, it just returns None).
This function allows a node to respond (answer back) directly to other nodes. An example will make
this clearer.
Imagine node A is loaded with a script containing the following function definition:
Page 68 of 202 SNAP Reference Manual Document Number 600-0007K