-
Notifications
You must be signed in to change notification settings - Fork 8
Making BERT RPC calls in C#
The full example is available in the C# example project here.
For more information regarding how BERT-RPC works, please refer to the BERT-RPC spec.
Before you can make BERT-RPC calls against a BERT-RPC server, you first need to create an instance of Filbert.Rpc.BertRpcClient
using the static Start
method:
var client = Filbert.Rpc.BertRpcClient.Start(serviceUrl, portNumber)
Once you have a client, use BertRpcClient.CallAsTask
to make a synchronous call against a BERT-RPC server, this will return an instance of Task<Bert>
which you can then use to get the response from the server.
Suppose there is a nat
Erlang module running on the BERT-RPC server, which looks like this:
-module(nat).
-export([add/2, die/1]).
add(A, B) -> A + B.
die(X) -> X = 10.
To call nat.add(1, 100)
and wait for the response synchronously, this is all you need to do:
var result = client.CallAsTask("nat", "add", Bert.NewInteger(1), Bert.NewInteger(100))
.Result;
To make a cast
call against a BERT-RPC server and wait for the acknowledgement synchronously:
client.CastAsTask("nat", "die", Bert.NewInteger(666)).Wait();
I decided to expose the xxxAsTask
methods in hope that it's async
ready in C# 5, but haven't got around to testing this very much at the time of this writing.
If you run into any problems/inconvenience using the RPC client within C# 5, please free feel to contact me and I'll do my best to resolve any issues you come across as soon as I can!