User manual

This is an exaggerated example, but the point is that somemes you are sending to mulple nodes because of
the importance of the command.
It is important to note that the funcon being called might make an RPC call of its own. For the sake of the
example, imagine a network of exactly two SNAP nodes “A” and “B” and imagine node B contains the following
script snippet:
def askSensorReading():
value = readSensor()
mcastRpc(1, 1, "tellSensorReading", value)
Now imagine node A contains the following script snippet:
def tellSensorReading(value):
print "I heard the sensor reading was ", value
If node A later does:
mcastRpc(1, 1, "askSensorReading")
then two procedure calls can occur. First node A will invoke askSensorReading() on node B, but then that roune
will invoke roune tellSensorReading() back on node A.
You should also be aware that even though a RPC call is made via mulcast, it sll is possible to have only a
single node completely process that call.
Imagine the above “two node network” is expanded with nodes “C”-“Z”, but that we also change to script to be:
def askSensorReading(who):
if who == localAddr(): # is this command meant for ME?
value = readSensor()
mcastRpc(1, 1, "tellSensorReading", value)
Assume nodes C-Z are loaded with the same script as node B. If node A later does:
mcastRpc(1, 1, "askSensorReading", address_of_node_B)
then even though all nodes within a one-hop radius will invoke funcon askSensorReading() only node B will
actually take a reading and report it back.
Of course, wanng to invoke a funcon on a single node is actually a prey common use case, which is where
the following funcon comes in.
Rpc(address, function, args…)
Built-in funcon rpc() is like mcastRpc(), but with two differences:
1) Instead of specifying a group and a number of hops (TTL Time To Live), with the rpc() funcon you specify
the actual SNAP Address of the intended target node
a) The SNAP Mesh roung protocol will take care of “finding” the node (if it can be found).
b) Other nodes (with different SNAP Addresses) will not perform the rpc() call, even if their currently
loaded SNAPpy script also contains the requested funcon. However they will (by default) assist in
delivering the rpc() call to the addressed node, if it is not in direct communicaon range of the source
node.
2) Instead of only sending the RPC call a single me (blindly) as mcastRpc() does, the rpc() funcon expects a
special ACK (acknowledgement) packet in return.
34 SNAP® Network Operang System