microsoft / vs-streamjsonrpc

The StreamJsonRpc library offers JSON-RPC 2.0 over any .NET Stream, WebSocket, or Pipe. With bonus support for request cancellation, client proxy generation, and more.
Other
730 stars 149 forks source link

Parent <-> child communication design. #1024

Closed slimshader closed 5 months ago

slimshader commented 5 months ago

Hi,

My case: launcher application that is able to spawn 2 child apps. I want my launcher and child apps be able to talk to each other via json rpc, meaning sending multiple messages back and forth when needed. Based on od cond sampes I implemented it this way:

  1. Launcher creates a server based on InOut NamedPipeServerStream with name "Parent"
  2. Launcher starts child app
  3. child app creates InOut server with generated name
  4. child creates NamedPipeClientStream to "Parent"
  5. child calls remote procedure on parent "ChildReady" with generated name as paramter
  6. Parent creates NPCS with child's name
  7. parent and child send messages to each other via respecitve Client streams
  8. server streams get recreated after each precessed message (via while (true) loops)

            while (true)
            {
                var stream = new NamedPipeServerStream("StreamJsonRpcSamplePipe", PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
    
                await stream.WaitForConnectionAsync();
    
                var jsonRpc = JsonRpc.Attach(stream, this);
    
                await jsonRpc.Completion;
            }

is that the way to go for this case?