User manual
This is an exaggerated example, but the point is that somemes you are sending to mulple nodes because of
the importance of the command.
It is important to note that the funcon 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 roune
will invoke roune tellSensorReading() back on node A.
You should also be aware that even though a RPC call is made via mulcast, it sll 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 funcon askSensorReading() only node B will
actually take a reading and report it back.
Of course, wanng to invoke a funcon on a single node is actually a prey common use case, which is where
the following funcon comes in.
Rpc(address, function, args…)
Built-in funcon 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() funcon you specify
the actual SNAP Address of the intended target node
a) The SNAP Mesh roung 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 funcon. However they will (by default) assist in
delivering the rpc() call to the addressed node, if it is not in direct communicaon range of the source
node.
2) Instead of only sending the RPC call a single me (blindly) as mcastRpc() does, the rpc() funcon expects a
special ACK (acknowledgement) packet in return.
34 SNAP® Network Operang System