Git Product home page Git Product logo

pipemethodcalls's Introduction

PipeMethodCalls

Lightweight .NET Standard 2.0 library to use method calls over named and anonymous pipes for IPC. Supports two-way communication with callbacks.

Calls from client to server

var pipeServer = new PipeServer<IAdder>(
    new NetJsonPipeSerializer(),
    "mypipe",
    () => new Adder());
await pipeServer.WaitForConnectionAsync();
var pipeClient = new PipeClient<IAdder>(new NetJsonPipeSerializer(), "mypipe");
await pipeClient.ConnectAsync();
int result = await pipeClient.InvokeAsync(adder => adder.AddNumbers(1, 3));

Calls both way

var pipeServer = new PipeServerWithCallback<IConcatenator, IAdder>(
    new NetJsonPipeSerializer(),
    "mypipe",
    () => new Adder());
await pipeServer.WaitForConnectionAsync();
string concatResult = await pipeServer.InvokeAsync(c => c.Concatenate("a", "b"));
var pipeClient = new PipeClientWithCallback<IAdder, IConcatenator>(
    new NetJsonPipeSerializer(),
    "mypipe",
    () => new Concatenator());
await pipeClient.ConnectAsync();
int result = await pipeClient.InvokeAsync(a => a.AddNumbers(4, 7));

About the library

This library uses named pipes to invoke method calls on a remote endpoint. The method arguments are serialized to binary and sent over the pipe.

Serialization

PipeMethodCalls supports customizable serialization logic through IPipeSerializer. You've got two options:

  • Use a pre-built serializer
    • new NetJsonPipeSerializer() from the PipeMethodCalls.NetJson package. That uses the System.Text.Json serializer that's built into .NET.
    • new MessagePackPipeSerializer() from the PipeMethodCalls.MessagePack package. That uses the MessagePack-CSharp serializer, which has excellent performance.
  • Plug in your own implementation of IPipeSerializer. Refer to the NetJsonPipeSerializer code for an example of how to do this.

Open an issue or pull request if you'd like to see more built-in serializers.

Features

  • 100% asynchronous communication with .ConfigureAwait(false) to minimize context switches and reduce thread use
  • 45KB with no built-in dependencies
  • Invoking async methods
  • Passing and returning complex types with pluggable JSON or binary serialization
  • Interleaved or multiple simultaneous calls
  • Throwing exceptions
  • CancellationToken support
  • Works on Windows, Linux and MacOS

Not supported

  • Methods with out and ref parameters
  • Properties
  • Method overloads

pipemethodcalls's People

Contributors

randomengy avatar lukelonas avatar rseanhall avatar kmgallahan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.