You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dynamic codegen of individual delegates to invoke RPC from client #673
do some thing.......
var dataChange=ServerJsonRpc.Attach<DataChange>( ClientInfo); //clientinfo is: client's stream /client's session(like ip and port) and so on
dataChange(newValue);
.......
I suppose we could technically add a method to JsonRpc that would generate code for a delegate of a given signature that would invoke some method. Your samples don't include the generation of this delegate taking the name of the server method though -- only the signature is given. Where does the method name come from?
That said, we already have robust support for convenient client proxies via our code generator that implements whole interfaces. Can you use that instead of doing it on a per-delegate basis?
Andrew Arnott (@AArnott)
i know .it is : You are talking about the interface of Client calling Server (client call server).
I want to express is: Server pushes messages to Client through "delegate event"
public delegate Task DataChange(int v);
server:
do some thing.......
var dataChange=ServerJsonRpc.Attach<DataChange>( ClientInfo); //clientinfo is: client's stream /client's session(like ip and port) and so on
dataChange(newValue);
.......
client:
ClientJsonRpc.AddDelegate<DataChange>((v)=>{Console.WriteLine(...............)});
Currently, vs-streamjsonrpc does not support "delegate event"
Thanks for helping me understand you're interested in reverse-direction RPC.
JSON-RPC is fundamentally a p2p protocol. So there isn't really a client or a server as far as the RPC protocol is concerned. This means you can define an interface for generating a proxy for each direction. What you think as your client and server can each have a unique interface, and they can invoke each other. This provides you one option for your "server" to invoke the client given the method signature you want, and any such method can be put into a delegate in your own code.
Did you know that the RPC interface can include events?
I'm sorry, I don't understand your question. Every event in C# is based on delegates. On the server and client you implement and add handlers to events as if it were ordinary C# code, and StreamJsonRpc makes them just work. If you're unfamiliar with events in C#, please learn that first then come back here if it works in the local case but not over RPC.
Activity
snikeguo commentedon Jun 1, 2021
snikeguo commentedon Jun 1, 2021
[-]I have a suggestion: [/-][+]Dynamic codegen of individual delegates to invoke RPC from client[/+]AArnott commentedon Jun 9, 2021
I suppose we could technically add a method to
JsonRpcthat would generate code for a delegate of a given signature that would invoke some method. Your samples don't include the generation of this delegate taking the name of the server method though -- only the signature is given. Where does the method name come from?That said, we already have robust support for convenient client proxies via our code generator that implements whole interfaces. Can you use that instead of doing it on a per-delegate basis?
snikeguo commentedon Jun 17, 2021
Andrew Arnott (@AArnott) My English is not very good. and I don't quite understand what you mean
This is an example:
https://github.com/beetlex-io/BeetleX-Samples/tree/master/XRPC.DelegateInvoke
Server:
https://github.com/beetlex-io/BeetleX-Samples/blob/69e9e0f15ea4d8bb4f8a740540d348866e415372/XRPC.DelegateInvoke/Server/Program.cs#L55
Client:
https://github.com/beetlex-io/BeetleX-Samples/blob/69e9e0f15ea4d8bb4f8a740540d348866e415372/XRPC.DelegateInvoke/Client/DelegateApi.cs#L10
AArnott commentedon Jun 21, 2021
In StreamJsonRpc this would look like:
On the server you could implement that interface.
On the client, you would then use:
snikeguo commentedon Jun 24, 2021
Andrew Arnott (@AArnott)
i know .it is : You are talking about the interface of Client calling Server (client call server).
I want to express is: Server pushes messages to Client through "delegate event"
Currently, vs-streamjsonrpc does not support "delegate event"
AArnott commentedon Jun 24, 2021
Thanks for helping me understand you're interested in reverse-direction RPC.
JSON-RPC is fundamentally a p2p protocol. So there isn't really a client or a server as far as the RPC protocol is concerned. This means you can define an interface for generating a proxy for each direction. What you think as your client and server can each have a unique interface, and they can invoke each other. This provides you one option for your "server" to invoke the client given the method signature you want, and any such method can be put into a delegate in your own code.
Did you know that the RPC interface can include events?
This can make it particularly convenient for a client/server paradigm designed interface to let the server call back to the client for notifications.
snikeguo commentedon Jun 24, 2021
yes ,i find a doc:
https://github.com/microsoft/vs-streamjsonrpc/blob/main/doc/dynamicproxy.md
but no sample.....only document
Where are examples of "delegate event"?
AArnott commentedon Jun 25, 2021
I'm sorry, I don't understand your question. Every event in C# is based on delegates. On the server and client you implement and add handlers to events as if it were ordinary C# code, and StreamJsonRpc makes them just work. If you're unfamiliar with events in C#, please learn that first then come back here if it works in the local case but not over RPC.