There is a client and a server that communicates through stdio. I think I am basically confused about the stdin and stdout. I have some questions about the stdio.
- Does the server read the request from stdin or stdout where the client writes to?
- Does the server write response to stdin or stdout where the client can read?
Below is the code snippet of connection part on server side.
case "stdio":
log.Println("server: reading on stdin, writing on stdout")
<-jsonrpc2.NewConn(context.Background(), jsonrpc2.NewBufferedStream(stdrwc{}, jsonrpc2.VSCodeObjectCodec{}), handler, connOpt...).DisconnectNotify()
log.Println("connection closed")
return nil
type stdrwc struct{}
func (stdrwc) Read(p []byte) (int, error) {
return os.Stdin.Read(p)
}
func (stdrwc) Write(p []byte) (int, error) {
return os.Stdout.Write(p)
}
func (stdrwc) Close() error {
if err := os.Stdin.Close(); err != nil {
return err
}
return os.Stdout.Close()
}