1 pub mod hello_world { 2 tonic::include_proto!("helloworld"); 3 } 4 5 pub mod echo { 6 tonic::include_proto!("grpc.examples.unaryecho"); 7 } 8 9 use echo::{echo_client::EchoClient, EchoRequest}; 10 use hello_world::{greeter_client::GreeterClient, HelloRequest}; 11 use tonic::transport::Endpoint; 12 13 #[tokio::main] main() -> Result<(), Box<dyn std::error::Error>>14async fn main() -> Result<(), Box<dyn std::error::Error>> { 15 let channel = Endpoint::from_static("http://[::1]:50051") 16 .connect() 17 .await?; 18 19 let mut greeter_client = GreeterClient::new(channel.clone()); 20 let mut echo_client = EchoClient::new(channel); 21 22 let request = tonic::Request::new(HelloRequest { 23 name: "Tonic".into(), 24 }); 25 26 let response = greeter_client.say_hello(request).await?; 27 28 println!("GREETER RESPONSE={:?}", response); 29 30 let request = tonic::Request::new(EchoRequest { 31 message: "hello".into(), 32 }); 33 34 let response = echo_client.unary_echo(request).await?; 35 36 println!("ECHO RESPONSE={:?}", response); 37 38 Ok(()) 39 } 40