.NET과 .core 사이의 간단한 IPC
이것은 .NET 또는 .core에서 사용되는 IPC의 번화이며 원하는 경우 혼합됩니다. 전환의 "수정"은 해킹이며 나중에 릴리스에 효과가 없을 수도 있습니다.
20.09.2020은 Netstandard 2.0과 .NET 4.7.2 사이에 예상대로 작동합니다.
클래스는 krakenipc : https://github.com/darksody/krakenipc 및 전체 듀플렉스 파이프를 기반으로합니다.
.NET472 응용 프로그램에서 데이터를 얻는 데 필요한 ASP.Core 응용 프로그램이 있었고 실제로 작동 한 유일한 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" ; }
}이제 서버를 작성하십시오. 필요한 것은 채널 이름 만 있으면됩니다. 이 파이프는 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 ( ) ) ;
}PipeConnection에는 예외 응용 프로그램이 필요합니다. "Connection 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 ( ) 모든 기여는 환영합니다 :)