Overview

Hello, and welcome to the VoltRpc documentation! These docs should hopefully contain the information you need in-order to use VoltRpc.

What is VoltRpc?

VoltRpc is a remote procedure call (RPC) library, using it's own custom implementation, which allows VoltRpc to be fast and easy to use.

This means you can call a C# method on a remote target (such as a separate process) using C# code.

VoltRpc's lowest .NET target is netstandard2.0, so you can use any .NET implementation that implements it.

Installation

VoltRpc can be installed from NuGet. You will also want VoltRpc's companion proxy .NET source generator. More info on the generator can be found on it's page.

You can add the NuGet packages using your IDE's NuGet package manager, or by adding it to your project's .csproj file.

<ItemGroup>
    <PackageReference Include="VoltRpc" Version="3.0.0" />
    <PackageReference Include="VoltRpc.Proxy.Generator" Version="2.1.0" />
</ItemGroup>

Unity

If you want to use VoltRpc with Unity, then install it using xoofx's UnityNuGet project. The packages are called org.nuget.voltrpc.

As Unity's .NET source generator compatibility is a bit... ifffy, the .NET source generator package has NOT been added to it.

Basic setup

Setting up VoltRpc is easy. VoltRpc has three parts; the host, the client and the proxy for the client.

Here is what a typical setup might look like.

Shared

using VoltRpc.Proxy;

namespace VoltRpcExample.Shared
{
    [GenerateProxy(GeneratedName = "TestProxy")]
    public interface ITest
    {
        public void Basic();
    }
}

Host

using System;
using System.Net;
using VoltRpc.Communication;
using VoltRpc.Communication.TCP;
using VoltRpcExample.Shared;

namespace VoltRpcExample
{
    public class Program
    {
        public static void Main()
        {
            Host host = new TCPHost(new IPEndPoint(IPAddress.Loopback, 7767));
            host.AddService<ITest>(new TestImpl());

            //NOTE: StartListening() is blocking, but there is an async version of the method
            host.StartListening();

            //Do whatever...
        }

        public class TestImpl : ITest
        {
            public void Basic()
            {
                Console.WriteLine("Hello!");
            }
        }
    }
}

Client

using System;
using System.Net;
using VoltRpc.Communication.TCP;
using VoltRpc.Proxy.Generated;
using VoltRpcExample.Shared;

namespace VoltRpcExample.Client
{
    public class Program
    {
        public static void Main()
        {
            VoltRpc.Communication.Client client = new TCPClient(new IPEndPoint(IPAddress.Loopback, 7767));
            client.AddService<ITest>();
            client.Connect();

            ITest testProxy = new TestProxy(client);

            //Call any method on the host via testProxy...
        }
    }
}

For a more in-depth setup that expends on this one, see the Setup section.