Skip to content

Repository files navigation

SimpleCrossFrameworkIPC

Simple IPC between .net and .core

This is a lightversion of a IPC to be used on either .net or .core and even mixed if you like. The "fix" for the conversion is a hack and might not work for later releases.

As for 20.09.2020 it works as expected between netstandard 2.0 and .net 4.7.2.

Class is based on KrakenIPC: https://github.com/darksody/KrakenIPC and Full Duplex Pipes: https://www.codeproject.com/Articles/1179195/Full-Duplex-Asynchronous-Read-Write-with-Named-Pip

Pipes are old, why did you mesh this up

I had a asp.core application that needed to get data from a .net472 application and the only IPC that actually worked was gRPC ( https://grpc.io/ ). gRPC was overkill for my project so I wanted something simpler and tiny.

Updated 20.09.2020

Added a custom delay for the time to wait for server data for the client. Changed return method to throw an exception instead of null, to make it easier to handle timeouts in the future. Also an event is added, to ensure that you catch everything if you decide to suppress exceptions.

Usage

Server and Client need to share a common interface.

publicinterfaceISimple{intNumber{get;}stringText{get;}}

Server contains the data in the interface, here presented as static values. You can use most common data types; int, string, char, float, double, long etc...

publicclassSimple:ISimple{publicintNumber{get=>111;}publicstringText{get=>"Some string";}}

Now create the server, all it needs is the channelname. Note that this pipe only works on localhost

try{//Then create servervarhandler=newSimpleCrossFrameworkIPC.Server<Simple,ISimple>();handler.Start("Channel");//Pause for clientsConsole.ReadLine();//Stop serverhandler.Stop();}catch(Exceptionex){Console.WriteLine(ex.ToString());}

When a client connects it will refer to the same interface. After connection are used to receive data from the server

intnWaitForServerDataDelay=2000;//2 sec max waiting for datavarclient=newSimpleCrossFrameworkIPC.Client<IMySimpleService>(nWaitForServerDataDelay);try{//Connect with a 1 second connection timeoutclient.Connect("Channel",1000);varproxy=client.GetProxy();//Print proxy-data to the consoleConsole.WriteLine("Text: "+proxy.Text);Console.WriteLine("Number: "+proxy.Number.ToString());}catch(Exceptionex){Console.WriteLine(ex.ToString());}

Exceptionhandling is needed for the pipeconnection throws a "Connection timout" and other errors.

Complexity

I have never used this class for complex classes and support for this is unknown.

Events and public functions

Server

Events

publiceventEventHandler<EventArgs> ClientConnected;publiceventEventHandler<EventArgs> ClientDisconnected;

Functions

voidStart(stringPipename)voidStop()publicTGetProxy()

Client

Events

publiceventEventHandler<EventArgs> ClientDisconnected;

Functions

voidConnect(stringPipename)voidConnect(stringPipename,intTimeout)publicvoidDisconnect()publicboolIsConnected()voidUseProxy(Action<T>callback)publicTGetProxy()

Contribution

Any contribution is welcome :)

About

Simple IPC between .net and .core

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages