Announcement

Collapse
No announcement yet.

Snap connect and callbacks

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Snap connect and callbacks

    Hi again!

    I have some odd behaviour here issuing a callback rpc from snapconnect to a snap node. If I call a function which does not exist, I get also the callback with the name of the not existing function as parameter. Is this intended?

  • #2
    Callback can be one of the more complicated functions to implement. I recommend thoroughly reading and re-reading the notes on p.43 of the Snap Reference Manual. But let me try and do my own explanation here as well...

    Code:
    rpc(remoteAddress, 'callback', 'LocalFunction', 'RemoteFunction', remoteFunctionArg1, remoteFunctionArg2, ...)
    Above you'll see the standard way that callback is utilized.

    First, you call "rpc" to send a message to a remote node. The "remoteAddress" is just the hex address of the, well, remote node. All well and good so far, and this is largely the standard way that everything in Snap works.

    "LocalFunction" and "RemoteFunction" are where things get complicated.

    Rather than having callback directly return the remote function's return value, you instead define a local function to receive any return value. When the above line of code executes and you drop out of your immediately running function, then you'll eventually get a return from the remote node to which you sent the rpc. At that point, you'll drop into the LocalFunction that you defined on the same node from which you originally called the rpc. As such, it's almost like LocalFunction *is* the return value from the remote node. You can either display that value, or perform some operation on that return value at that time.

    RemoteFunction is the actual function that the rpc/callback combo initiates on the remote node. If that RemoteFunction takes arguments, then you can add them to the original rpc/callback call. Those arguments are the remoteFunctionArg1, remoteFunctionArg2, etc. You don't have to have any remoteFunctionArgs. You can just specify the RemoteFunction and then close parenthesis to call the remote function with no args. Or you can have an arbitrary number of arguments... don't try too many. I forget what the limit is, but you'll start running into just wireless transmit issues beyond some threshold. Three or Four arguments should be guaranteed fine, though.

    As for your original question of doing a callback with no defined function, well, I'd call that "undefined behavior". Let's get everything defined as per the instructions above and troubleshoot from there.

    Comment


    • #3
      Ok. But then there must be way to request whether the remote function is present or not.

      Comment

      X