HandyIpc 0.5.3
Requires NuGet 2.12 or higher.
dotnet add package HandyIpc --version 0.5.3
NuGet\Install-Package HandyIpc -Version 0.5.3
<PackageReference Include="HandyIpc" Version="0.5.3" />
paket add HandyIpc --version 0.5.3
#r "nuget: HandyIpc, 0.5.3"
// Install HandyIpc as a Cake Addin #addin nuget:?package=HandyIpc&version=0.5.3 // Install HandyIpc as a Cake Tool #tool nuget:?package=HandyIpc&version=0.5.3
HandyIpc
English | 中文
HandyIpc is an out-of-the-box inter-process communication (IPC) library, similar to WCF for remote method calls, but lighter in comparison, eliminating all the tedious configuration. You only need to read this README from the beginning to the master.
This library provides a high-level RMI (remote method invocation) API. Its underlying communication can be implemented by whatever you like, such as Named Pipe, MMF (memory mapping file) or Socket, and this framework does not care about the specific implementation.
NuGet
Install Packages
Add the following 3 packages to your project.
Note: HandyIpc.NamedPipe
and HandyIpc.Socket
only need to install one, it is recommended to choose HandyIpc.NamedPipe
, it is faster than HandyIpc.Socket
.
<PackageReference Include="HandyIpc" Version="0.5.2" />
<PackageReference Include="HandyIpc.NamedPipe" Version="0.5.0" />
<PackageReference Include="HandyIpc.Serializer.Json" Version="0.5.0" />
How to use
1. Define IPC contract
// Declare an interface contains a set of methods that needs to be called remotely,
// and mark it with IpcContractAttribute.
[IpcContract]
// Feature: Supports generic interfaces.
public interface IDemo<T>
{
Task<T> GetDefaultAsync();
double Add(double x, double y);
// Feature: Supports Task/Task<T> async methods.
Task<double> AddAsync(double x, double y);
// Feature: Supports generic methdos.
string GetTypeName<T>();
}
2. Implement, register IPC contract in server side
// Implement the IPC contract (interface).
public class Demo<T> : IDemo<T>
{
public Task<T> GetDefaultAsync() => Task.FromResult<T>(default);
public double Add(double x, double y) => x + y;
public Task<double> AddAsync(double x, double y) => Task.FromResult(x + y);
public string GetTypeName<T>() => typeof(T).Name;
}
// Create a ContainerServerBuilder instance to build the IContainerServer instance.
ContainerServerBuilder serverBuilder = new();
serverBuilder
//.UseTcp(IPAddress.Loopback, 10086)
.UseNamedPipe("ec57043f-465c-4766-ae49-b9b1ee9ac571")
.UseJsonSerializer();
serverBuilder
// Generic interfaces that are not monomorphic need to be registered in this form.
.Register(typeof(IDemo<>), typeof(Demo<>))
// Non-generic interfaces or generic interfaces that are already monomorphic can use more elegant extension methods.
.Register<IDemo<string>, Demo<string>>()
.Register<ICalculator, Calculator>();
using var server = serverBuilder.Build();
// Don't forget to start the server.
server.Start();
// server.Stop();
3. Invoke remote methods in client side
// Create a ContainerClientBuilder instance to build the IContainerClient instance.
ContainerClientBuilder clientBuilder = new();
clientBuilder
//.UseTcp(IPAddress.Loopback, 10086)
.UseNamedPipe("ec57043f-465c-4766-ae49-b9b1ee9ac571")
.UseJsonSerializer();
using var client = clientBuilder.Build();
// Resolve contract instances from the client instance.
var demo1 = client.Resolve<IDemo<string>>();
var demo2 = client.Resolve<IDemo<int>>();
// Using contract instances, they will call an implementation from another process.
var result0 = demo1.Add(16, 26); // 42
var result1 = await demo1.AddAsync(40, 2); // 42
var result2 = demo1.GetTypeName<string>(); // "String"
var result3 = await demo1.GetDefaultAsync(); // null
var result3 = await demo2.GetDefaultAsync(); // 0
TODO List
- Support for generic interface.
- Support for
Task/Task<T>
return value in interface method. - Support for generic methods (parameter type allow contains nested generic types).
- NOT support for interface inheritance.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on HandyIpc:
Package | Downloads |
---|---|
Fly.Toolkit.Wpf
请无视它,它并不好用,只是能给我自己带来一点点的便利而已 |
|
HandyIpc.NamedPipe
A handy inter-process communication library. |
|
HandyIpc.Serializer.Json
A handy inter-process communication library. |
|
HandyIpc.Socket
A handy inter-process communication library. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.5.3 | 619 | 10/3/2022 |