LibRPC
1.0.0
LibRPC 是一個非常輕量、即時且高效能的函式庫,適用於 .Net Framework 和 .Net Portable。它提供基於流的 RPC 框架,這使得它非常輕且可擴展。它基本上適用於伺服器/客戶端和請求/回應架構。查看基本使用範例
LibRPC 使用基於流的通信,因此您可以在 TCP、管道和任何其他基於流的協定中使用它。以下是基本的伺服器-客戶端範例,我們簡單地呼叫伺服器來新增兩個數字Imports LibRPC.Basic
:
Private Sub Server()
Dim tcp As New TcpListener(IPAddress.Loopback, 11221 )
tcp.Start()
While True
Dim sock = tcp.AcceptTcpClient()
Dim host = New RPCHost(sock.GetStream())
host.On( 6644 , New Func( Of Integer , Integer , Integer )( AddressOf OnAdd))
End While
End Sub
Private Function OnAdd(x As Integer , y As Integer ) As Integer
Return x + y
End Function
Private Sub Client()
Dim tcp As New TcpClient( "localhost" , 11221 )
Dim host As New RPCHost(tcp.GetStream())
Console.WriteLine(host.Call( Of Integer )( 6644 , 5 , 9 )) '14
End Sub
以下是using LibRPC.Basic;
:
private void Server ( )
{
TcpListener tcp = new TcpListener ( IPAddress . Loopback , 11221 ) ;
tcp . Start ( ) ;
while ( true ) {
dynamic sock = tcp . AcceptTcpClient ( ) ;
dynamic host = new RPCHost ( sock . GetStream ( ) ) ;
host . On ( 6644 , new Func < int , int , int > ( OnAdd ) ) ;
}
}
private int OnAdd ( int x , int y )
{
return x + y ;
}
private void Client ( )
{
TcpClient tcp = new TcpClient ( "localhost" , 11221 ) ;
RPCHost host = new RPCHost ( tcp . GetStream ( ) ) ;
Console . WriteLine ( host . Call < int > ( 6644 , 5 , 9 ) ) ; //14
}