func (s *MyServer) MyStreamRPC(req *MyRequest, stream MyService_MyStreamRPCServer) error { for i := 0; i < 10; i++ { resp := &MyResponse{Data: fmt.Sprintf("Message %d", i+1)} if err := stream.Send(resp); err != nil { return err } } return nil }
stream, err := client.NewStream(ctx, &grpc.StreamDesc{ StreamName: "MyStreamRPC", ServerStreams: true, ClientStreams: true, }, "/my-service/MyStreamRPC") if err != nil { return err } for i := 0; i < 10; i++ { msg := &MyRequest{Data: fmt.Sprintf("Request %d", i+1)} if err := stream.SendMsg(msg); err != nil { return err } }In summary, the google.golang.org/grpc/transport Stream package provides gRPC clients and servers the ability to establish bidirectional and unidirectional streams for sending and receiving data.