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
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.
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.
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.
I have never used this class for complex classes and support for this is unknown.
publiceventEventHandler<EventArgs> ClientConnected;publiceventEventHandler<EventArgs> ClientDisconnected;voidStart(stringPipename)voidStop()publicTGetProxy()publiceventEventHandler<EventArgs> ClientDisconnected;voidConnect(stringPipename)voidConnect(stringPipename,intTimeout)publicvoidDisconnect()publicboolIsConnected()voidUseProxy(Action<T>callback)publicTGetProxy()Any contribution is welcome :)