> For the complete documentation index, see [llms.txt](https://docs.atsign.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.atsign.com/atsdk/atsdk-walkthroughs/atsdk-tutorial/rpc.md).

# Remote Procedure Calls (RPC)

## Do something remotely and send back the answer.

RPC has been a design pattern for decades, and, no surprise, we have RPC in the atSDK also.  This demo code is in another directory named `at_rpc_demo`. You can get to it by using VS Code and open folder and select that folder. Next, once again, open two windowpanes.

In the right-hand pane enter (again using your Atsigns!)

```
dart pub get
```

This pulls in needed libraries, and then this starts the RPC listener.

```
dart pub get
dart run .\bin\arithmetic_server.dart -a "@energetic22" -n "atsign" --allow-list "@7capricorn"
```

Then in the left window, you can run up the client

```
dart run .\bin\arithmetic_client.dart -a "@7capricorn" -n "atsign" --server-atsign "@energetic22"
```

You will get a prompt after a second or two and you can put in a math expression and hit enter. The expression will be sent to the other Atsign, the answer calculated, and then returned.&#x20;

See our session in action:

<figure><img src="/files/JAjfnDjBKYOOv2mm9trl" alt=""><figcaption><p>RPC</p></figcaption></figure>

Something to notice here is that the RPC server will only respond to RPCs from the designated Atsign with the `--allow-list` argument.

The RPC can, of course, do anything you want it to, and the Atsigns can be running anywhere.

### The code

An AtRpc object is set up pretty simply with:

```dart
    var rpc = AtRpc(
      atClient: atClient,
      baseNameSpace: atClient.getPreferences()!.namespace!,
      domainNameSpace: 'at_rpc_arithmetic_demo',
      callbacks: DemoRpcServer(),
      allowList: allowList,
    );

    rpc.start();
  } catch (e) {
    print(e);
    print(CLIBase.argsParser.usage);
  }
```

The Callbacks are sent to the `DemoRpcServer`class and handled appropriately.

On the sending side the RPC client is initiated:

```dart
    var rpc = AtRpcClient(
        atClient: atClient,
        baseNameSpace: atClient.getPreferences()!.namespace!,
        domainNameSpace: 'at_rpc_arithmetic_demo',
        serverAtsign: serverAtsign);
```

Then the RPC simple sent and awaiting a reply

```dart
var response = await rpc.call({'expr': expr}).timeout(Duration(seconds: 5));
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.atsign.com/atsdk/atsdk-walkthroughs/atsdk-tutorial/rpc.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
