SimpleCrossFrameworkIPC
Release 1.1.4.4
.NET和.CORE之間的簡單IPC
這是IPC的燈光,可在.NET或.CORE上使用,甚至混合在一起。轉換的“修復程序”是一個黑客,可能不適用於以後的版本。
至於20.09.2020,它在NetStandard 2.0和.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
我有一個ASP.CORE應用程序,需要從.NET472應用程序中獲取數據,而實際工作的唯一IPC是GRPC(https://grpc.io/)。 GRPC對我的項目過大,所以我想要一些簡單,更小的東西。
添加了一個時間的自定義延遲,以等待客戶端的服務器數據。更改返回方法以投擲異常而不是null,以使將來更容易處理超時。還添加了一個事件,以確保如果您決定抑制異常,則可以捕獲所有事件。
服務器和客戶端需要共享一個通用接口。
public interface ISimple
{
int Number { get ; }
string Text { get ; }
}服務器包含接口中的數據,此處以靜態值表示。您可以使用最常見的數據類型; int,string,char,float,double,long等...
public class Simple : ISimple
{
public int Number { get => 111 ; }
public string Text { get => "Some string" ; }
}現在創建服務器,它所需的只是ChannelName。請注意,該管道僅適用於Localhost
try
{
//Then create server
var handler = new SimpleCrossFrameworkIPC . Server < Simple , ISimple > ( ) ;
handler . Start ( "Channel" ) ;
//Pause for clients
Console . ReadLine ( ) ;
//Stop server
handler . Stop ( ) ;
}
catch ( Exception ex )
{
Console . WriteLine ( ex . ToString ( ) ) ;
}當客戶端連接時,它將參考相同的接口。連接後用於從服務器接收數據
int nWaitForServerDataDelay = 2000 ; //2 sec max waiting for data
var client = new SimpleCrossFrameworkIPC . Client < IMySimpleService > ( nWaitForServerDataDelay ) ;
try
{
//Connect with a 1 second connection timeout
client . Connect ( "Channel" , 1000 ) ;
var proxy = client . GetProxy ( ) ;
//Print proxy-data to the console
Console . WriteLine ( "Text: " + proxy . Text ) ;
Console . WriteLine ( "Number: " + proxy . Number . ToString ( ) ) ;
}
catch ( Exception ex )
{
Console . WriteLine ( ex . ToString ( ) ) ;
}管道連接需要異常授權會引發“連接timout”和其他錯誤。
我從來沒有將此課用於復雜的課程,對此的支持是未知的。
public event EventHandler < EventArgs > ClientConnected ;
public event EventHandler < EventArgs > ClientDisconnected ; void Start ( string Pipename )
void Stop ( )
public T GetProxy ( ) public event EventHandler < EventArgs > ClientDisconnected ; void Connect ( string Pipename )
void Connect ( string Pipename , int Timeout )
public void Disconnect ( )
public bool IsConnected ( )
void UseProxy ( Action < T > callback )
public T GetProxy ( ) 歡迎任何貢獻:)