1 #[cfg(unix)] 2 3 pub mod hello_world { 4 tonic::include_proto!("helloworld"); 5 } 6 7 use hello_world::{greeter_client::GreeterClient, HelloRequest}; 8 use http::Uri; 9 use std::convert::TryFrom; 10 use tokio::net::UnixStream; 11 use tonic::transport::Endpoint; 12 use tower::service_fn; 13 14 #[tokio::main] 15 async fn main() -> Result<(), Box<dyn std::error::Error>> { 16 // We will ignore this uri because uds do not use it 17 // if your connector does use the uri it will be provided 18 // as the request to the `MakeConnection`. 19 let channel = Endpoint::try_from("lttp://[::]:50051")? 20 .connect_with_connector(service_fn(|_: Uri| { 21 let path = "/tmp/tonic/helloworld"; 22 23 // Connect to a Uds socket 24 UnixStream::connect(path) 25 })) 26 .await?; 27 28 let mut client = GreeterClient::new(channel); 29 30 let request = tonic::Request::new(HelloRequest { 31 name: "Tonic".into(), 32 }); 33 34 let response = client.say_hello(request).await?; 35 36 println!("RESPONSE={:?}", response); 37 38 Ok(()) 39 } 40