-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client Over WebSocket #6
Comments
To solve my current problem, I design a simple version of JsonRPC , it only support notification call , and it's peer to peer. |
I'm not sure what exactly peer-to-peer means in the context of JsonRPC, but two parties using JsonRPC 2.0 can still communicate duplexly as long as the channel is duplex. And each party can share a same channel both for RPC server and client, because when receiving messages from one side of the channel, you can never confuse a) a JsonRPC request/notification from other side with b) a JsonRPC response from other side for a request previsouly sent from this side. Thus you, at the end of one side of the pipe, just need to pick out these two kind of messages, and feed them to corresponding JsonRPC server/client handler. For example, console is duplex, because stdin/stdout are actually two streams, and Language Server Protocol uses JsonRPC over stdio as communication protocol. LSP client (e.g. VSCode IDE) can do RPC invocation on LSP server (e.g. OmniSharp LSP server) and get response (e.g. get all the workspace symbols), while LSP server can also do RPC invocation on LSP client and get response (e.g. show confirmation dialog on LSP client). By invocation I mean either For WebSocket-based LSP server/client implementation, you may consider derive a class from |
@CXuesong Thanks for your answer. but I still a little bit confusing, Is that means as a WebSocket |
Yes, if you want your HTTP server to be able to make call to HTTP client side, in addition to calling HTTP server from client side. In this case, you also need both JSON-RPC client and server waiting on your HTTP server. Note that these calls can happen in one WebSocket connection. Also note that LSP is just a higher-level protocol that happens to use JSON-RPC 2.0 as transport protocol. LSP requires LSP server can call LSP client and vice versa, so when implementing LSP, we usually use a pair of JSON-RPC server and client handler logic both on the LSP server, and on the LSP client. Thus at this degree, I believe JSON-RPC 2.0 itself is one-directional (A calls B, but B cannot call A). Yet we may well put a pair of JSON-RPC server and client to achieve bi-directional calls.
When I used "duplex", I only meant "bi-directional calls". I don't think it's a common vocabulary when discussing JSON-RPC 😋 And if you are using WebSocket, I don't think |
Okay so now we have I have an example on how to use it to setup a JSON-RPC server on WebSocket server with ASP.NET Core in If you are going to use this package on your WebSocket client, keep in mind So the rest of work is that you need to instantiate a And please note that being a WebSocket client does not necessarily means you couldn't be a JSON-RPC server. |
@CXuesong Great work ! 👍 bacause the |
I need two way communication(the server need to send a
Notification
to my client, and it does not know client ip address)I can successfully connect the server via
System.Net.WebSockets.ClientWebSocket
, but It does not useStream
(it use aArraySegment<byte>
)Is that still possible to use this library?
The text was updated successfully, but these errors were encountered: